Tips and Tricks
How to get value for a property from a object in Powershell Variable ?
PowerShell is a very unique and powerful language. Objects are the main reason behind it. It’s default use of object makes it different then any other shell or scripting language.
Objects are everywhere in PowerShell. I will not waste any more time with some random information here so lets get back to our original question.
How to get value for a property from every object in Powershell Variable?
Lets take an example ! I want to fetch object id of AD group
PS> Get-AzADGroup -DisplayName "my-group" | Select Idoutput will be like -
Id
--
2xc3cc-3frf5g-r4fe34c-xxxxx-something
However, this use of the Select-Object
cmdlet (built-in alias is select
) is not much of use here as this still returns a object that requires you to access its property again !
We can use Select-Object to extract a single property value, via
-ExpandProperty <PropertyName> parameter:PS> Get-AzADGroup -DisplayName "developers" | Select
-ExpandProperty Id
2xc3cc-3frf5g-r4fe34c-xxxxx-something