Get all IPs from an Azure account

Get all IPs from an Azure account

avatar

Hello,

Here is a Powershell cmdlet provided by one of our customers. It gets all IPs from an Azure account and import them to a Data Source XML file based.

$file = "$env:USERPROFILE\AppData\Local\Devolutions\RemoteDesktopManager\Connections.xml"

# Check if Data Source exists

if (-not (Test-Path $file)) {

$XmlWriter = New-Object System.XMl.XmlTextWriter($file,$Null)

$xmlWriter.WriteStartDocument()

$xmlWriter.WriteStartElement("ArrayOfConnection")

$xmlWriter.WriteStartElement("Connection")

$xmlWriter.WriteEndElement

$xmlWriter.WriteEndElement

$xmlWriter.Finalize

$xmlWriter.Flush

$xmlWriter.Close()

}

# Logs in to Azure

Login-AzureRmAccount

$azureAccount = 'your Azure ID account'

Select-AzureRmSubscription -SubscriptionId $azureAccount

# Gets all IPs and stores them to the XML file

$ips = Get-AzureRmPublicIpAddress

foreach ($ip in $ips) {

Write-Host $ip.Name "and" $ip.IpAddress

$xml = [xml](Get-Content $file)

$connection = $xml.CreateElement("Connection")

$connectionType = $xml.CreateElement("ConnectionType")

$connectionType.InnerXml = "RDPConfigured"

$connection.AppendChild($connectionType)

$credentialConnectionID = $xml.CreateElement("CredentialConnectionID")

$credentialConnectionID.InnerXml = "b35609a2-5d5a-480e-8e74-95900801fb85"

$connection.AppendChild($credentialConnectionID)

$group = $xml.CreateElement("Group")

$group.InnerXml = $ip.ResourceGroupName

$connection.AppendChild($group)

$id = $xml.CreateElement("ID")

$id.InnerXml = [guid]::NewGuid()

$connection.AppendChild($id)

$name = $xml.CreateElement("Name")

$name.InnerXml = $ip.Name

$connection.AppendChild($name)

$openEmbedded = $xml.CreateElement("OpenEmbedded")

$openEmbedded.InnerXml = "true"

$connection.AppendChild($openEmbedded)

$url = $xml.CreateElement("Url")

$url.InnerXml = $ip.IpAddress

$connection.AppendChild($url)

$xml.ArrayOfConnection.AppendChild($connection)

$xml.Save($file)

}

Best regards,

Érica Poirier

All Comments (0)