Cannot update column data in Excel file
Ntinsky opened this issue · comments
Hi everyone
I have an xls file which contains User data like Name,Surname.email,username,Password (These are the columns in order)
I wrote a script which is using the Import-Excel convert it to CSV and reads data which tried to match match t a user domain account.
Once the user matches it changes the domain user password and stores the password in an array:
$userDataArray += [PSCustomObject]@{ Password = $password }
So far i can update the Password header in the CSV file with the $password
I am trying to do the same with the Excel file and update the appropriate Password column with $password using some code below without results. The 'Password' column remains empty so i don't know what am i missing here
The code
$sourcefile=C:\temp\UserData.xlsx
# Import Excel file
$originalExcel = Import-Excel -Path $sourcefile
# Update the "Password" column in the Excel file with the passwords from the array
for ($i = 0; $i -lt $originalExcel.Count; $i++) {
$originalExcel[$i]."Password" = $passwordArray[$i]
}
# Export the updated CSV file
$originalExcel | Export-Excel -Path $sourcefile -NoHeader -AutoSize -ClearSheet -PassThru