Created
May 6, 2020 09:17
-
-
Save SQLtattoo/9f4f47d2f782652d850f7060561ca57c to your computer and use it in GitHub Desktop.
Assign Network 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 "nsg-nointernet" Network Security Group must exist | |
$VMs = Get-AzVM | where Name -Like "APPSRV-*" | |
foreach ($VM in $VMs) { | |
$nic = Get-AzNetworkInterface -ResourceId $VM.NetworkProfile.NetworkInterfaces.id | |
$Nsg = Get-AzNetworkSecurityGroup -Name "nsg-nointernet" | |
Write-Output "Adding NSG: $Nsg to $VM" | |
$nic.NetworkSecurityGroup = $Nsg | |
$nic | Set-AzNetworkInterface | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment