Curious if there is any hidden way to reference a property without typing out the property name. I know I could create a bunch of variables to use in place of the full name, but I'm surprised the data's headers aren't 'Gettable' by their relative position.
I'm working with CSVs right now specifically, but here's an example of what I'm trying to do - let's say I want to update a bunch of fields, but typing ."First Name"
sucks...Is there anyway to substitute something like $_.Column2
?
$data = Import-CSV .\data.csv | %{If($_."First Name" -eq "Bob"){$_."First Name" = "Robert"};$_}
Example data.csv
Employee's ID First Name Last Name Phone Number
------------- ---------- --------- ------------
12345 Bob Jackson 555-555-5555
67891 Jessie Jackson 123-456-7891
I want to make it clear that I don't have any problems with Bob, but I can't find much out about PSObject Properties and I figured there might be some hidden gem in there that I don't know about. I also know that this would make longer scripts harder to read and more difficult to troubleshoot in the future, but for quick things it would be helpful.
As an aside, here are a few of the things I've considered implementing -
- Creating variables for each column and using
$1
,$2
, etc. - Import the data using different headers (like col1, col2, etc.) and then fix the headers when I'm done