Last active
February 24, 2017 15:43
-
-
Save stuartleeks/8436568 to your computer and use it in GitHub Desktop.
PowerShell script to create a Remote Desktop Connection Manager configuration file for all Windows Azure Virtual Machines in a subscription.Requires Azure PowerShell cmdlets: http://www.windowsazure.com/en-us/documentation/articles/install-configure-powershell/. See this blog post for more info: http://blogs.msdn.com/b/stuartleeks/archive/2014/0…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$rdcmanName = "Azure VMs" | |
$outputFileName = Get-Location | Join-Path -ChildPath "AzureVMs.rdg" | |
$xml = [xml]'<?xml version="1.0" encoding="utf-8"?> | |
<RDCMan schemaVersion="1"> | |
<version>2.2</version> | |
<file> | |
<properties> | |
<name>blog</name> | |
<expanded>True</expanded> | |
<comment /> | |
<logonCredentials inherit="FromParent" /> | |
<connectionSettings inherit="FromParent" /> | |
<gatewaySettings inherit="FromParent" /> | |
<remoteDesktop inherit="FromParent" /> | |
<localResources inherit="FromParent" /> | |
<securitySettings inherit="FromParent" /> | |
<displaySettings inherit="FromParent" /> | |
</properties> | |
<group> | |
<properties> | |
<name>a group</name> | |
<expanded>False</expanded> | |
<comment /> | |
<logonCredentials inherit="FromParent" /> | |
<connectionSettings inherit="FromParent" /> | |
<gatewaySettings inherit="FromParent" /> | |
<remoteDesktop inherit="FromParent" /> | |
<localResources inherit="FromParent" /> | |
<securitySettings inherit="FromParent" /> | |
<displaySettings inherit="FromParent" /> | |
</properties> | |
<server> | |
<name>myservername</name> | |
<displayName>my display name</displayName> | |
<comment /> | |
<logonCredentials inherit="FromParent" /> | |
<connectionSettings inherit="None"> | |
<connectToConsole>False</connectToConsole> | |
<startProgram /> | |
<workingDir /> | |
<port>12345</port> | |
</connectionSettings> | |
<gatewaySettings inherit="FromParent" /> | |
<remoteDesktop inherit="FromParent" /> | |
<localResources inherit="FromParent" /> | |
<securitySettings inherit="FromParent" /> | |
<displaySettings inherit="FromParent" /> | |
</server> | |
</group> | |
</file> | |
</RDCMan>' | |
$fileElement =$xml.RDCMan.file | |
$groupTemplateElement =$xml.RDCMan.file.group | |
$fileElement.properties.name = $rdcmanName | |
Get-AzureService | %{ | |
$service = $_ | |
$gotVmWithRdpEndpoint = $false | |
$groupElement = $groupTemplateElement.Clone() | |
$groupElement.properties.name = $service.ServiceName | |
$serverTemplateElement = $groupElement.server | |
Get-AzureVM -ServiceName $service.ServiceName | %{ | |
$vm = $_ | |
$rdpEndpoints = @($vm.VM.ConfigurationSets.InputEndpoints | ?{$_.LocalPort -eq 3389}) | |
if($rdpEndpoints.Length -gt 0){ | |
# got a Remote Desktop endpoint | |
# add the server element | |
$serverElement = $serverTemplateElement.Clone() | |
$address = $vm.DNSName | |
$serverElement.name = $vm.DNSName.TrimStart("http://").TrimEnd("/") | |
$serverElement.displayName = $vm.Name | |
$serverElement.connectionSettings.port = $rdpEndpoints[0].Port.ToString() | |
$groupElement.AppendChild($serverElement) | out-null | |
$gotVmWithRdpEndpoint = $true | |
} | |
} | |
if($gotVmWithRdpEndpoint){ | |
$groupElement.RemoveChild($serverTemplateElement) | out-null | |
($fileElement.AppendChild($groupElement)) | out-null | |
} | |
} | |
$fileElement.RemoveChild($groupTemplateElement) | out-null | |
$xml.Save($outputFileName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment