Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AndrewPla/650209134a3ea887a31104085628bd9c to your computer and use it in GitHub Desktop.
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.
# 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
}
@AndrewPla
Copy link
Author

@NathWork
Copy link

Thank you. Precisely what I needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment