Backup your Server Roles and Features
The following short script gathers the installed roles and features on a server and outputs them to PowerShell script that can be used to redeploy them on another server. This can be useful during migration scenarios or when you need to deploy an additional server with the same requirements.
Copy the below code and save it as a ps1 file.
$roles = Get-WindowsFeature | Where {$_.installed -eq "Installed"} | Select Name
$command = "Add-WindowsFeature "
ForEach ($role in $roles){
$command += $role.Name + ","
}
$command = $command.Substring(0,$command.Length-1)
New-Item -Path C:\ -Name "ServerRoles.ps1" -ItemType File -Value $command
When complete produces another ps1 file called ServerRoles.ps1 on the root system drive. Open the file to reveal the install command
Don’t forget if your script is for server 2012, as you need .NetFx3 then you will need to append –Source <path to sxs folder here> to the end of the script.

Mark is an Independent Microsoft Teams Consultant with over 15 years experience in Microsoft Technology. Mark is the founder of Commsverse, a dedicated Microsoft Teams conference and former MVP. You can follow him on twitter @UnifiedVale
Reblogged this on We Speak Binary and commented:
Not just for Skype for Business – this powershell script gathers the installed components for any Windows server, allowing you to automate server run-ups for whatever you’re building. Excellent work!
Mark,
Great and useful script, will most certainly give this a go. A question however, would this backup the config for each of the roles as well or is there a separate step required to do this?
Thanks,
Omar
No literally just grabs the installed roles and produces a PS script to reinstall them as new