전체 원격 데스크톱 세션 배포를 자동화하려고 하지만 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.

이 문제를 해결하는 데 도움이 되는 로그가 하나도 없습니다.

서버 관리자로 이동하여 이 UI를 통해 추가하면: 여기에 이미지 설명 입력

모든 것이 예상대로 작동합니다. 이 작업을 수행하려면 추가 단계가 필요합니까?

현재 실행 중인 스크립트(EC2, userdata)는 다음과 같습니다.

<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>
no answer