How to get an object's property's value by property name?

前端 未结 6 1659
野趣味
野趣味 2020-11-27 14:54

In PowerShell, how do you get an object\'s property value by specifying its name (a string)? I want something like the following:

$obj = get-something

# Vie         


        
6条回答
  •  失恋的感觉
    2020-11-27 15:40

    Expanding upon @aquinas:

    Get-something | select -ExpandProperty PropertyName
    

    or

    Get-something | select -expand PropertyName
    

    or

    Get-something | select -exp PropertyName
    

    I made these suggestions for those that might just be looking for a single-line command to obtain some piece of information and wanted to include a real-world example.

    In managing Office 365 via PowerShell, here was an example I used to obtain all of the users/groups that had been added to the "BookInPolicy" list:

    Get-CalendarProcessing conferenceroom@domain.com | Select -expand BookInPolicy
    

    Just using "Select BookInPolicy" was cutting off several members, so thank you for this information!

提交回复
热议问题