Created
January 6, 2019 19:21
-
-
Save AndrewPla/650209134a3ea887a31104085628bd9c to your computer and use it in GitHub Desktop.
iterate through all properties on a pscustomobject. This is example code to accompany a blogpost.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a pscustomobject from a hashtable | |
$object = [pscustomobject]@{ Key1 = 'Val1' ; Key2 = 'Val2' } | |
# Grab all noteproperty members | |
$objMembers = $object.psobject.Members | where-object membertype -like 'noteproperty' | |
foreach ($member in $objMembers) { | |
# Now you can do what you want with the name and value. | |
$Member.name | |
$Member.Value | |
} |
Thank you. Precisely what I needed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://andrewpla.github.io/Iterate-Over-Object-Properties/