如何启用远程桌面用户 - Azure服务的后部署/后期构建

时间:2015-03-18 07:16:02

标签: azure rdp azure-cloud-services azure-powershell azure-deployment

想知道是否有办法启用RDP后部署。发布云服务?

在打包之前可以使用选项来执行此操作!

1 个答案:

答案 0 :(得分:0)

为此找到了一个有效的解决方案!

设置-AzureServiceRemoteDesktopExtension

您需要将ServiceName传递给下面的代码段。

        if(($UserName) -and ($Password))
        {
            $SecurePass = ConvertTo-SecureString -string $Password -AsPlainText -Force
            $Credential = New-Object System.Management.Automation.PSCredential $UserName, $SecurePass

            # Check if RDP is enabled for the Service
            $isRDPEnaled = Get-AzureServiceRemoteDesktopExtension -ServiceName $ServiceName
            if(!$isRDPEnaled)
            {
                # Enable RDP with the new user
                Set-AzureServiceRemoteDesktopExtension -ServiceName $ServiceName -Credential $Credential
            }
            else
            {
                if($isRDPEnaled.UserName -ne $UserName)
                {
                    # Remove RDP for the existing user
                    Remove-AzureServiceRemoteDesktopExtension -ServiceName $ServiceName
                    # Enable RDP with the new user
                    Set-AzureServiceRemoteDesktopExtension -ServiceName $ServiceName -Credential $Credential
                }
                else
                {
                    Write-Verbose ""
                    Write-Verbose " Remote Login enabled for the Service "
                }
            }
        }