Author Posts

July 26, 2018 at 9:36 pm

Had anyone been able to come up with a one liner to get all virtual network objects across all subscriptions?

I am trying to create a dynamic param that retrieves all vnet objects.

I tried
Get-azurermsubscription | set-azuremcontext; get-azurermvirtualnetwork inside foreach or foreach-object but couldn't get itto work right.

Any help is appreciated greatly.

Thank you Jason

July 27, 2018 at 12:56 am

Why would it have to be a one-liner if it's in a script?
I get it if you are doing this interactively in the PS consolehost.
A dynamicParameter can be a dataset from whatever collection you pass to it.

Secondly, this...

Get-azurermsubscription | set-azuremcontext; get-azurermvirtualnetwork

… is two completely separate commands. Semi colon, does not make it a one-line, just separate command on the same line (code break). You cannot pass results from the left side of the semi colon to anything on the right.

The above is really just this...

Get-azurermsubscription | set-azuremcontext
get-azurermvirtualnetwork

You need to find as matching property or value between these two to get what you are after, just as you would with non-Azure cmdlet table / data matches.

Get-azurermsubscription | %{get-azurermvirtualnetwork}