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

image

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.

3 thoughts on “Backup your Server Roles and Features

  1. 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!

    Like

    1. 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

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s