Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Assign Network Security Group to Azure VMs
# 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