Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SQLtattoo/d95eb2412e02dfac4f46de1b369adaca to your computer and use it in GitHub Desktop.
Save SQLtattoo/d95eb2412e02dfac4f46de1b369adaca to your computer and use it in GitHub Desktop.
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