Script: List empty vnet

Introduction When working in Azure or the rest of the Microsoft Cloud environment. One of the preferred tools are Powershell. From time to time, I have customers or random people on docs.microsoft.com Q&A area asking question that is solvable using a script. If I have the time or if the question peaked… Read more
17 Apr, 2023

Introduction

When working in Azure or the rest of the Microsoft Cloud environment. One of the preferred tools are Powershell. From time to time, I have customers or random people on docs.microsoft.com Q&A area asking question that is solvable using a script.

If I have the time or if the question peaked my interest, I will do what I can to help in providing or finding a solution.

So, I decided to share these scripts here with a description of function and in some cases a description of what the different cmdlets do. I would like to note that these are scripts that I have used or provided for a specific purpose and thus, they are limited in features to what is required of them.

The idea is that if you are searching for a specific issue, you might come across this blog post – in which case one of the scripts might be able to help you out with the the task you try to accomplish.

All scripts will be located in this public Github repository and are everyone is allowed to use or modify them within the boundary of the MIT License.

List empty vnet

This script were created due to what seems to be an expanded wish to clean up on orphan resources in Azure environments. So this script runs through either a specific subscription or all subscriptions in a tenant and looks for all empty vnets.

It is mandatory to provide the tenantID from the tenant in question, and if a subscription name or ID is provided, then it will only look through the resources in this specific subscription.

The result will be saved on the following location “C:\Temp\empty vnet list.csv” unless another position is specified using the -exportpath variable

Required modules

The script

The result

The result will be a CSV file that you can open in your preferred CSV editor, which contains the following headlines

  • VNETname
  • VNETRessourcegroup
  • VNETLocation
  • VNETResourceGuid
  • subscriptionName
  • subnetname
  • subnetIPconfig
  • subnetResourceNavigationLinks
  • subnetServiceAssociationLinks
  • subnetNetworkSecurityGroup
  • subnetRouteTable
  • subnetNatGateway
  • subnetServiceEndpoints
  • subnetServiceEndpointPolicies
  • subnetPrivateEndpoints
  • subnetEndpointNetworkPolicies
  • subnetLinkServiceNetworkPolicies
  • tenantid
  • VNETId
  • subscriptionId
  • subnetid

Final thoughts

Thank you for reading through this post. Hopefully, it helped you solve a problem or you might just have used it for getting inspiration for a script yourself.

If you have any questions or feedback, please feel free to comment here in the comments or using the contact form

0 Comments

About Martin Meiner Tästensen

I am a positive minded It professional, with more than 10 years of experience in various IT roles. I love to build, create and see how an idea can become a system affecting hundreds or thousands of employees – and at the same time try to make the system work as smooth as possible to give the best end user experience. My Primary focus for the first decade of my career has been towards classic infrastructure where I worked with a deep knowledge level on both network and servers – where the latter has ranged from physical servers, over OS layer and all the way to the services installed on the server.