r/PowerShell • u/Zealous_Automation • Apr 26 '26
Changing values of elements in an array
I just figured out how to reference individual elements in an array. But I can't seem to modify the element values
I start off with a $data = import-csv -path "path\to\file.csv"
Then do some loops. For debugging, I'm outputting the values in the part of the loop where I'm modifying values:
$data.OffLastName[$jj]
$data.ReportsToLast[$jj]
$data.managerid[$jj]
$Manager = "Manager"
$Manager
$data.ManagerID[$jj] = $Manager
$data.ManagerID[$jj]
And the output looks like this:
Brown
Young
{null} (I've also tested this as "XXXXXXXXX")
Manager
{null} (This resulted in XXXXXXXXX during my other test)
Based off my test code, I want the last {null} value to reflect "Manager" and I can't figure out what I'm doing wrong. I've also attempted to fill the values on the .csv with text to see if it was a string vs number mismatch on variable type.
I could use some help because I feel like its something obvious. But according to google searches, it seems like I'm doing it right.
View all comments
Show parent comment
2
u/Zealous_Automation Apr 26 '26
Disregard. I'm understanding your explanation now.
$data.ManagerID[$jj] = $Manager
$data.ManagerID[$jj]
This didn't work because after that first line executes the temporary array goes away.
When it goes to display that second line, it recreates the temporary array with original values from $data.