ARM-wvd-templates/DSC/Script-AddRdshServer.ps1 (45 lines of code) (raw):

<# .SYNOPSIS Creating Hostpool and add sessionhost servers to existing/new Hostpool. .DESCRIPTION This script add sessionhost servers to existing/new Hostpool The supported Operating Systems Windows Server 2016. .ROLE Readers #> param( [Parameter(mandatory = $true)] [string]$HostPoolName, [Parameter(Mandatory = $true)] [string]$RegistrationInfoToken, [Parameter(mandatory = $false)] [switch]$EnableVerboseMsiLogging ) $ScriptPath = [system.io.path]::GetDirectoryName($PSCommandPath) # Dot sourcing Functions.ps1 file . (Join-Path $ScriptPath "Functions.ps1") # Setting ErrorActionPreference to stop script execution when error occurs $ErrorActionPreference = "Stop" Write-Log -Message "Creating a folder inside rdsh vm for extracting deployagent zip file" $DeployAgentLocation = "C:\DeployAgent" ExtractDeploymentAgentZipFile -ScriptPath $ScriptPath -DeployAgentLocation $DeployAgentLocation Write-Log -Message "Changing current folder to Deployagent folder: $DeployAgentLocation" Set-Location "$DeployAgentLocation" # Checking if RDInfragent is registered or not in rdsh vm if (Test-path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\RDInfraAgent") { $regTokenProperties = Get-ItemProperty -Path hklm:SOFTWARE\Microsoft\RDInfraAgent -Name "RegistrationToken" -ErrorAction SilentlyContinue $isRegisteredProperties = Get-ItemProperty -Path hklm:SOFTWARE\Microsoft\RDInfraAgent -Name "IsRegistered" -ErrorAction SilentlyContinue $CheckRegistry = ($regTokenProperties.RegistrationToken -eq "") -and ($isRegisteredProperties.isRegistered -eq 1) } Write-Log -Message "Checking whether VM was Registered with RDInfraAgent" if ($CheckRegistry) { Write-Log -Message "VM was already registered with RDInfraAgent, script execution was stopped" } else { Write-Log -Message "VM not registered with RDInfraAgent, script execution will continue" Write-Log "AgentInstaller is $DeployAgentLocation\RDAgentBootLoaderInstall, InfraInstaller is $DeployAgentLocation\RDInfraAgentInstall" InstallRDAgents -AgentBootServiceInstallerFolder "$DeployAgentLocation\RDAgentBootLoaderInstall" -AgentInstallerFolder "$DeployAgentLocation\RDInfraAgentInstall" -RegistrationToken $RegistrationInfoToken -EnableVerboseMsiLogging:$EnableVerboseMsiLogging Write-Log -Message "The agent installation code was successfully executed and RDAgentBootLoader, RDAgent installed inside VM for existing hostpool: $HostPoolName" }