Created
July 28, 2015 14:24
-
-
Save Kevin-Bronsdijk/8e9e21f4582ba3d1d739 to your computer and use it in GitHub Desktop.
automatically-remove-azure-rdp-endpoints
This file contains hidden or 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
$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 | |
} | |
} |
This file contains hidden or 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
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