我正在尝试自动执行完整的远程桌面会话部署,但在通过 powershell 添加网关时遇到问题。我可以添加除网关之外的每个服务器。这会产生错误:
Unable to create a Remote Desktop resource authorization policy on <computer name>. The error is
Object reference not set to an instance of an object.. Please check the eventlog on RD Gateway server for more info.
我在任何日志中都看不到任何可以帮助我解决此问题的内容。
一切按预期进行。是否需要其他步骤才能实现?
这是当前正在运行的脚本(EC2,用户数据):
<powershell>
try {
$SecretAD = "SuperSecretSauceSuzzySaid"
$SecretObj = (Get-SECSecretValue -SecretId $SecretAD)
}catch {
Write-Output 'Failed to get Secret'
return
}
$sys = Get-WmiObject -Class Win32_ComputerSystem
if ( -Not ($sys.PartOfDomain))
{
Write-Output "Not A domain member yet. Joining..."
[PSCustomObject]$Secret = ($SecretObj.SecretString | ConvertFrom-Json)
$password = $Secret.password | ConvertTo-SecureString -asPlainText -Force
$username = $Secret.username
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
Write-Output "Starting Domain Join and Restarting"
Add-Computer -DomainName "6565.fake.com" -Credential $credential -Restart -Force
Write-Output "Initiating restart..."
}
Try {
$process = (Get-NetAdapterBinding -InterfaceAlias "Ethernet" -ComponentID ms_tcpip6).Enabled
If ($process.toString() -ne "False"){
Get-NetAdapterBinding –InterfaceAlias "Ethernet"
Disable-NetAdapterBinding –InterfaceAlias "Ethernet" –ComponentID ms_tcpip6
Write-Output "Disabled ipv6"
Import-Module RemoteDesktop
Add-WindowsFeature –Name RDS-RD-Server –IncludeAllSubFeature
Write-Output "Restarting..."
Restart-Computer -Force
}
Start-Sleep 200
$installed = (Get-WindowsFeature RDS-RD-Server).Installed
If ($installed.toString() -eq "True"){
$broker = (Get-WindowsFeature RDS-Connection-Broker).Installed
If ($broker.toString() -eq "False"){
$ErrorActionPreference = 'SilentlyContinue'
Write-Output "Installing the new session deployment"
New-RDSessionDeployment -ConnectionBroker "$env:COMPUTERNAME.6565.fake.com" -SessionHost "$env:COMPUTERNAME.6565.fake.com"
Write-Output "Restarting..."
Restart-Computer -Force
}
}
Start-Sleep -Seconds 100
New-RDSessionCollection -CollectionName QuickSessionCollection -SessionHost "$env:COMPUTERNAME.6565.fake.com" -CollectionDescription "POR Stuff" -ConnectionBroker "$env:COMPUTERNAME.6565.fake.com"
Write-Output "Installing Gateway with managnent tools"
Add-WindowsFeature -Name RDS-Gateway -IncludeManagementTools -ComputerName $env:COMPUTERNAME
Start-Sleep -Seconds 100
Add-RDServer -Server "$env:COMPUTERNAME.6565.fake.com" -Role "RDS-GATEWAY" -ConnectionBroker "$env:COMPUTERNAME.6565.fake.com" -GatewayExternalFqdn "6565.fake.com"
Add-RDServer -Server "$env:COMPUTERNAME.6565.fake.com" -Role "RDS-LICENSING" -ConnectionBroker "$env:COMPUTERNAME.6565.fake.com"
} Catch [System.Exception] {
Write-Output "Failed"
Write-Output "Failed to install RD Gateway components $_"
Exit 0
}
</powershell>
<persist>true</persist>
答案1
我猜想不存在具有您网关名称的计算机。我猜想在$sys = Get-WmiObject -Class Win32_ComputerSystem
您获得空 $sys 之后。
尝试使用以下工具调试脚本powershell ide。