Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Kevin-Bronsdijk/8e9e21f4582ba3d1d739 to your computer and use it in GitHub Desktop.
Save Kevin-Bronsdijk/8e9e21f4582ba3d1d739 to your computer and use it in GitHub Desktop.
automatically-remove-azure-rdp-endpoints
$endpointName = "RemoteDesktop"
$vms = Get-AzureVM | SELECT ServiceName, Name
Foreach ($vm in $vms)
{
$vmConfig = Get-AzureVM -ServiceName $vm.ServiceName -Name $vm.Name
# if found, remove and update
if ($vmConfig | Get-AzureEndpoint -Name $endpointName)
{
$vmConfig | Remove-AzureEndpoint -Name $endpointName
$vmConfig | Update-AzureVM
}
}
workflow RemoveRDPEndpoints
{
$Cred = Get-AutomationPSCredential -Name "auto"
Add-AzureAccount -Credential $Cred
$endpointName = "RemoteDesktop"
$vms = Get-AzureVM | SELECT ServiceName, Name
Foreach -Parallel ($vm in $vms)
{
# if found, remove and update
$endpoint = Get-AzureEndpoint -VM (Get-AzureVM -ServiceName $vm.ServiceName -Name $vm.Name) -Name $endpointName
if ($endpoint)
{
InlineScript
{
$vmc = Get-AzureVM -ServiceName $Using:vm.ServiceName -Name $Using:vm.Name
$vmc | Remove-AzureEndpoint -Name $Using:endpointName
$vmc | Update-AzureVM
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment