A powerful, yet easy solution to simplify the process of recreating the OfficeWebApps Farm after an upgrade. As mentioned in the article from Microsoft Technet, when you want to apply a patch and/or upgrade to the OfficeWebApps software, you need to remove the OfficeWebApps Machine (Remove-OfficeWebAppsMachine
) prior to the upgrade and recreate the Farm (New-OfficeWebAppsFarm
) afterwords.
This seems a bit uneasy, because you need to get every parameter of the current Farm (Get-OfficeWebAppsFarm
). Also you need to do this every time you update to the latest ServicePack or Cumulative Update.
This solution automates that part, by writing the current config to CSV and loading it in to recreate the Farm with exactly the same config.
The first part is just plain and simple, export the config to CSV, don’t forget any Host config (allowed domains), than remove the OfficeWebApps Machine.
1 2 3 4 5 |
Import-Module OfficeWebApps Get-OfficeWebAppsFarm | Export-Csv .\OWAFarm.csv (Get-OfficeWebAppsHost).allowList | Select @{N='Domain';E={$_}} | Export-Csv .\OWAFarmDomains.csv Remove-OfficeWebAppsMachine |
The next part recreates the OfficeWebApps Farm based on the CSV, which checks the parameters of the “New-OfficeWebAppsFarm” and converts booleans from the CSV where needed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
Import-Module OfficeWebApps $OldFarm = Import-Csv .\OWAFarm.csv #Loop through each parameter that is available from the command New-OfficeWebAppsFarm, # take the key and validate if it's not empty in the imported CSV. $NewOfficeWebAppsFarmParameters = (Get-Command New-OfficeWebAppsFarm).Parameters.Keys | ?{$OldFarm.$_ -ne '' -and $OldFarm.$_ -ne $null} #Initiate the hashtable $NewFarm = @{} #Loop through the filtered parameterset, for each parameter: # take the value from the imported CSV, # convert to boolean or when it fails just use value as-is, # add the value to the hashtable with the parameter as key. Foreach($OWAParam in $NewOfficeWebAppsFarmParameters) { Try{ $Value = [System.Convert]::ToBoolean($OldFarm.$OWAParam) }Catch{ $Value = $OldFarm.$OWAParam }; $NewFarm.Add($OWAParam, $Value) } #Recreate the OfficeWebApps Farm with the hashtable using splatting technique '@' New-OfficeWebAppsFarm @NewFarm -Confirm:$False #Recreate Hosts/domains if any: Import-Csv .\OWAFarmDomains.csv | %{New-OfficeWebAppsHost -Domain $_.Domain} #Export new farm, so you can manualy compare the CSV's Get-OfficeWebAppsFarm | Export-Csv .\OWAFarm_new.csv |
By using a hashtable for the parameters, it is easy to use it with the “New-OfficeWebAppsFarm” command. This technique (using a ‘@’ in front of the hashtable variable) is called splatting, check this blog for more on that.
Happing upgrading!