mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
個人BLOG
it developer
  1. Main page
  2. M365
  3. Main content

powershell ExpandProperty和ExpandResource用法

2020-11-23 102hotness 0likes 0comments

ExpandProperty

http://www.datawan.net/web/index.php/cloud/45-powershell-expandproperty

As most of you already know the "-ExpandProperty" parameter
let's you enumerate the values of an incoming object as single value. 
For example, if you run the command below without the "-ExpandProperty".


Get-AzLocalNetworkGateway -ResourceGroupName "network-rg"

You will get output like this:↓↓↓↓↓
Name                     : my-lng
ResourceGroupName        : network-pd-rg
Location                 : southcentralus
Id                       : /subscriptions/GUID/resourceGroups/network-pd-rg/providers/Microsoft.Network/localNetworkGateways/qco-houdc-lng
Etag                     : W/"GUID"
ResourceGuid             : GUID
ProvisioningState        : Succeeded
Tags                     : ・・・
GatewayIpAddress         : 4.50.4.28
LocalNetworkAddressSpace : {
                             "AddressPrefixes": [
                               "10.100.0.0/16",
                               "10.101.0.0/16",
                               "10.102.0.0/16",
                               "10.103.0.0/16",
                               "10.104.0.0/16",
                             ]

                           }
BgpSettings              : null

But what if you just want a simple list of all LocalNetworkAddressSpace? 
You can use -ExpandProperty but the trick is you have to use it twice! 
See sample below. 
If you only pass it once you will still not get desired list,
you must expand the properties two times because the expanded property is a list in this case.


Get-AzLocalNetworkGateway -ResourceGroupName "network-rg" | Select -ExpandProperty LocalNetworkAddressSpace | Select -ExpandProperty AddressPrefixes | FT

Tag: Nothing
Last updated:2020-11-23

mikebai

This person is a lazy dog and has left nothing

Like
< Last article
Next article >

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang