Search code examples
azurerdpazure-cloud-servicesazure-powershellazure-deployment

How to enable Remote Desktop User - Post Deployment/ Post Build for Azure Services


Would like to know if there is a way to enable RDP post Deployment. Post Build of a Cloud Service?

Options are available before packaging to do this!


Solution

  • Found a working solution for this!

    Set-AzureServiceRemoteDesktopExtension

    You need the ServiceName to be passed to the snippet below.

            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 "
                    }
                }
            }