Get all virtual networks from all subscriptions in azure?

Welcome Forums General PowerShell Q&A Get all virtual networks from all subscriptions in azure?

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
3 months, 2 weeks ago.

  • Author
    Posts
  • #105409

    Participant
    Points: 1
    Rank: Member

    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

  • #105437

    Participant
    Points: 206
    Helping Hand
    Rank: Participant

    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}
    

The topic ‘Get all virtual networks from all subscriptions in azure?’ is closed to new replies.