Get Azure Networking Hierarchy Components With Powershell

I needed to see what VNETs, their subnets and the NIC/IPs attached to those subnets which is all available in Azure Portal but I wanted a nice hierarchical listing so here is a Powershell script for that…

$vnets = Get-AzVirtualNetwork
foreach ($vnet in $vnets)
{
"VNET: " + $vnet.Name
"Subnet Count: " + $vnet.Subnets.count
foreach ($subnet in $vnet.Subnets)
{
"..Subnet: " + $subnet.Name
if ($Subnet.IpConfigurations.count -eq 0)
(more...)

Azure Advisor And Fixing Errors

Azure can be configured to send you advisor reports detailing things that are not quite right in your environment. The advisor is not necessarily always right but it’s sensible to review the outputs periodically, even if they relate to non production environments.

A few issues popped up on an advisor report on my recent travels and although you can just use the entries on the report on the portal to target the offending resources, I (more...)

Finding databases on each SQL Server using Powershell

A client had the requirement to list out the SQL Servers and the databases they have installed on those SQL Servers in their Azure Cloud environment this week. The reason for the requirement was to find SQL Servers that no longer had any databases on them so they could be considered for removal.

Essentially, it gathers a list of SQL Server resources, loops through them and counts and itemises them, not including the master database (more...)

Azure Active Directory (AAD)

Find the ID of an existing user:

PS Azure:> $azureaduser=$(az ad user list --filter "userPrincipalName eq 'Fred.Smith@acme.com'" --query [].objectId --output tsv)

Azure:/

PS Azure:> $azureaduser

a5cga394-f1da-4f2c-bc4b-931c10bad9e1

Show all users in AAD:

az ad user list --query [].userPrincipalName

Virtual Machines (VMs)

Getting an Image

$Location="northeurope"
Get-AzureRmVMImagePublisher -Location $Location
Get-AzureRmVMImageOffer -Location $Location -PublisherName "MicrosoftSQLServer"
Get-AzureRmVMImageSku -Location $Location -PublisherName "MicrosoftSQLServer" -Offer "SQL2019-WS2016"
Get-AzureRmVMImage -Location $Location -PublisherName "MicrosoftSQLServer" -Offer "SQL2019-WS2016" -Skus "SQLDEV"

Tagging

Show tags for all resources

az group list --query [].tags 

Create tag

az tag create --name "Review Date"

Create tag with values

az tag add-value --name Environment --value Development

Set a tag to a value for a resource group

az group update -n example-resource-group --set tags.Environment=prod tags.CostCenter=IT