Powershell: install RDS Terminal Server Gateway SSL Certificate

Solution 1:

You need to ensure the TSGateway service is stopped before you set the thumbprint. So in your second example you should do:

# $NewThumb obtained elsewhere from the certificate 
Import-Module RemoteDesktopServices -ErrorAction SilentlyContinue
Stop-Service TSGateway
write-host "Before"
$th=Get-Item -Path RDS:\GatewayServer\SSLCertificate\Thumbprint
$th | fl  
Set-Item RDS:\GatewayServer\SSLCertificate\Thumbprint -Value $NewThumb
Start-Service TSGateway 
write-host "after"    
$TH=Get-Item -Path RDS:\GatewayServer\SSLCertificate\Thumbprint
$th | fl

This is sadly not documented but this has been my experience after setting this up internally at Microsoft.