
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to retrieve the Azure VM network security group (NSG) using PowerShell?
To retrieve the Azure VM NSG name using PowerShell, we first need to retrieve the NIC name of the VM.
PS C:\> $vm = Get-AzVM -VMName Win2k16VM1 PS C:\> $vmnic = $vm.NetworkProfile.NetworkInterfaces.Id.Split('/')[-1]
The above command will retrieve the name of the VM. To get the network security Group (NSG) name, we can use the below command.
PS C:\> (Get-AzNetworkInterface -Name $nic).NetworkSecurityGroup.Id.Split('/')[-1]
The above command will retrieve the name of the VM. To get the network security Group (NSG) name, we can use the below command.
PS C:\> (Get-AzNetworkInterface -Name $nic).NetworkSecurityGroup.Id.Split('/')[-1]
You can use the below code to get all the details.
Get-AzVM -VMName Win2k16VM1 | Select Name, ResourceGroupName, ` @{N='NIC';E={ $_.NetworkProfile.NetworkInterfaces.ID.Split('/')[-1]}}, ` @{N='NSG';E={ $nic = $_.NetworkProfile.NetworkInterfaces.ID.Split('/')[-1] (Get-AzNetworkInterface -Name $nic).NetworkSecurityGroup.Id.Split('/')[-1] }}
Output
- Related Questions & Answers
- How to retrieve the Azure VM resource group using PowerShell?
- How to retrieve the Azure VM NIC name using PowerShell?
- How to retrieve the Azure VM vNet name using PowerShell?
- How to retrieve the Azure VM Subscription Name using PowerShell?
- How to retrieve the Azure VM deallocated date using PowerShell?
- How to retrieve the Azure VM nic name using Azure CLI in PowerShell?
- How to retrieve the OS of the Azure VM using Azure CLI in PowerShell?
- How to retrieve the Operating system of the Azure VM using PowerShell?
- How to retrieve the Azure VM RAM and CPU size using PowerShell?
- How to retrieve the OS caching setting of Azure VM using Azure\nCLI in PowerShell?
- How to get the Application security groups of the Azure VM using PowerShell?
- How to retrieve the Azure subnets connected to the virtual network using PowerShell?
- How to deallocate the Azure VM using Azure CLI in PowerShell?
- How to stop the Azure VM using Azure CLI in PowerShell?
- How to start the Azure VM using Azure CLI in PowerShell?
Advertisements