Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Assign Application Security Group to Azure VMs
# The "asg-appservers" Application Security Group must exist
#Get all the VMs that their name start with APPSRV-
$VMs = Get-AzVM | where Name -Like "APPSRV-*"
foreach ($VM in $VMs) {
$nic = Get-AzNetworkInterface -ResourceId $VM.NetworkProfile.NetworkInterfaces.id
$Asg = Get-AzApplicationSecurityGroup -Name "asg-appservers"
Write-Host Adding ASG: $Asg.Name to $VM.Name
$nic.IpConfigurations[0].ApplicationSecurityGroups = $Asg
$nic | Set-AzNetworkInterface
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment