function Install-ServerFeaturesAndRoles { <# .SYNOPSIS Installs the features and roles required to run and maintain ORB #> [CmdletBinding()] [OutputType([System.Boolean])] Param() $logLead = (Get-LogLeadName) $restartRequired = $false Write-Host "$logLead : Preparing to Install Windows Features" $features = (Get-RequiredServerFeaturesAndRoles) if (Test-IsWindowsServer) { Write-Host "$logLead : Server OS Detected. Importing ServerManager Module" Import-Module ServerManager | Out-Null } foreach ($featureSet in $features) { Write-Verbose "$logLead : Preparing to install feature set $($featureSet.Name)" foreach ( $feature in $featureSet.Features ) { if ( $null -eq ( Get-WindowsFeature -Name $feature ) ) { Write-Warning "$logLead : Feature set $($featureSet.Name) contains feature $feature that does not exist; skipping." Write-Warning "Review the results before continuing with the installation!" } else { $result = (Install-WindowsFeature -Name $feature -ErrorAction SilentlyContinue -Verbose:$false) Write-Verbose "$logLead : $($featureSet.Name) : $feature : Exit code is $($result.ExitCode), RestartRequired is $($result.RestartNeeded)" if ($result.ExitCode -notin [Microsoft.Windows.ServerManager.Commands.FeatureOperationExitCode]::Success, ` [Microsoft.Windows.ServerManager.Commands.FeatureOperationExitCode]::NoChangeNeeded, ` [Microsoft.Windows.ServerManager.Commands.FeatureOperationExitCode]::SuccessRestartRequired) { # Exit early on failure Write-Error "$logLead : $($featureSet.Name) feature $feature failed to install with exit code $($result.ExitCode)." return $false } elseif ($result.RestartNeeded -ne [Microsoft.Windows.ServerManager.Commands.RestartState]::No) { # Log that a restart is required but go ahead and install the rest Write-Warning "$logLead : A restart is required to complete installation of $($featureSet.Name) $feature" $restartRequired = $true } } } } return ($restartRequired -eq $false) }