Azure DevOps - Workload Identity Federation
In a previous blog post, I discussed Workload Identity Federation in AKS, the successor to the Azure Pod Identity solutions and a more elegant
I was working on an Azure deployment recently and I needed a very quick way to get all the endpoints and local IP from the Azure VMs, rather than clicking threw the portal and copying the endpoints one by one so I opened up the PowerShell ISE, struggled a bit with the Azure cmdlets and presto, got a nice one liner that gives me all the information I need.
Here is is:
Get-AzureVM -ServiceName $ServiceName -PipelineVariable AzureVM | Get-AzureEndpoint | Select-Object @{n='VMName'; e={($AzureVM).InstanceName}},@{n='IPAddress'; e={$AzureVM.IpAddress}}, @{n='ServiceDNS'; e={($AzureVM).DNSName}}, Name, Port | Format-Table -AutoSize
And the output should be something like this:
Note: My VMs were offline while I was writing this blog post, that’s why the IPAddress column is not populated
Now that we have a working one liner, let’s break it up on multiple lines to read it better:
Get-AzureVM -ServiceName $ServiceName -PipelineVariable AzureVM | Get-AzureEndpoint | Select-Object -Property @{ n = 'VMName' e = { ($AzureVM).InstanceName } }, @{ n = 'IPAddress' e = { $AzureVM.IpAddress } }, @{ n = 'ServiceDNS' e = { ($AzureVM).DNSName } }, Port, Name | Format-Table -AutoSize
So we are getting all the VMs that are in a service then we are defining a variable named ‘AzureVM’ that will contain all the returned objects from the Get-AzureVM command, then piping the output to Get-AzureEndpoint, and piping that output to the Select-Object command where I opened up three hash tables to create some calculated properties based on my needs then piped all that output to Format-Table and got everything that I needed in the form I needed.
Now in order to get some output from those calculated properties I needed the VM names and that information doesn’t get to the second pipeline thus the need for a PipelineVariable.
Happy PowerShelling!