powershell split multiple lines

Xu, Tao 40 Reputation points

I am runing

$vn = Get-AzVirtualNetwork -Name mynet
$vn.Subnets | Select Name, AddressPrefix,id | sort AddressPrefix

How may I list resourcegroup name which is in id?

A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
1,297 questions
0 comments No comments
{count} votes

Accepted answer
  1. anza 196 Reputation points

    are you asking for resource group of vn?

    or do you expect subnets to have different resourcegroupname?
    in that case by string manipulation you get the ResourceGroupNameFromId via

    $vn.Subnets | Select Name, AddressPrefix,@{n='ResourceGroupNameFromId';e={((($_.Id -split '/resourceGroups/')[1]) -split '/providers/')[0]}} | sort AddressPrefix

    property 'ID' was replaced by 'ResourceGroupNameFromId'


    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful