Select Page

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:

And the output should be something like this:

VM-Format

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:

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!

 

Pin It on Pinterest