Skip to content
Menu
Tech Automation Blog
  • About Author
  • Contact
Tech Automation Blog

Azure Network Interface Card status report using Powershell

Posted on August 17, 2019February 27, 2022

Update : updated script to support Azure Az powershell module.

Today, I am back with another inventory type powershell script. I recently wrote this to generate Azure Network Interface Card(NIC) details in an Azure Subscription.

I wrote this script to identify any orphan NIC with Public IP not attached to any VM . Though , it is not very expensive, we still need to delete those as it adds to the Azure consumption bill. You may refer to following Azure Cost Calculator for detailed pricing – https://azure.microsoft.com/en-us/pricing/details/ip-addresses/ .

Before start using this script, make sure, you have Azure Az Module installed and imported on the system. For more information on how to install and configure Az module refer following article : https://docs.microsoft.com/en-us/powershell/azure/new-azureps-module-az?view=azps-5.5.0

Let me know if it helps you!

$currentDir = $(Get-Location).Path
$oFile = "$($currentDir)\AzureNIC_Details.csv"

if(Test-Path $oFile){Remove-Item $oFile -Force}
"ResourceGroupName,NICName,AttachedVM,ProvisioningState,Location" | Out-File $oFile -Append -Encoding ASCII
Get-AzNetworkInterface | ForEach-Object{
	$rgName = $nicName = $provState = $location = $managedBy = ""
	$rgName = $_.ResourceGroupName
	$nicName = $_.Name
	$managedBy = if($_.VirtualMachine){$_.VirtualMachine.Id.split("/")[-1]}
	$provState = $_.ProvisioningState
	$location = $_.Location	
	"$rgName,$nicName,$managedBy,$provState,$location" | Out-File $oFile -Append -Encoding ASCII
}

Download above script and save it with a .ps1 file extension. Open powershell console. After that, login to your Azure account using – Login-AzAccount. It will prompt you to enter your Azure credentials.

This image has an empty alt attribute; its file name is image-3.png
Login to Azure Account

After you login to Azure, run the powershell script saved in previous step.

Run Powershell script

You will receive a csv file output like below:

CSV File output

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
May 2025
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« May    

Recent Posts

  • Monitor and alert Azure Service Health issues May 5, 2020
  • AWS IAM User access review May 3, 2020
  • Integrate Azure Security Center with Event Hub April 28, 2020
  • Add Tags to Azure Subscription April 24, 2020
  • Automate Azure billing report in Excel March 6, 2020

Categories

©2025 Tech Automation Blog | Powered by SuperbThemes