I'm working on a script and I want to let the user pass me the name of an object's property. Basically like Format-List and Format-Table do. You can tell them which properties to display. I'm sure it's possible inside a script (as opposed to a compiled cmdlet).
Something like this:
param([string]$propertyName)
Write-Host $_.$propertyName #that doesn't work
Write-Host $_.Property[$propertyName] #that doesn't work either
I thought about doing it with Invoke-Expression but that seemed like overkill. I'm sure there's an easier, more PowerShell-ish way to do it. I bet it's something that will seem totally obvious once I see it.
I've done the typical things with get-member to try to figure it out and I've Googled for it. I tried searching these forums but the search feature appears to be non-functional for me. I hope this isn't a question that's already been answered 100 times around here.
Thanks for the help.