Last active
June 15, 2020 12:07
-
-
Save SQLtattoo/d95eb2412e02dfac4f46de1b369adaca to your computer and use it in GitHub Desktop.
Assign Application Security Group to Azure VMs
This file contains 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
# 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