How to get the Application security groups of the Azure VM using PowerShell?


To get the Application security groups of the Azure VM using PowerShell, we need to first get the Network Interface of the Azure VM.

The below command will retrieve the NIC name of the Azure VM.

PS C:\> $vm = Get-AzVM -Name TestVM
$nic = (($vm.NetworkProfile.NetworkInterfaces.id).Split('/'))[-1]

Once we have the NIC name, we can use the Get-AzNetworkInterface command to retrieve the NIC information and the Security group.

The below command will retrieve the application security group names using PowerShell.

PS C:\> $nicsettings = Get-AzNetworkInterface -Name $nic
$nicsettings.IpConfigurations.ApplicationSecurityGroups

Updated on: 31-Aug-2021

417 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements