Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot update column data in Excel file #83

Open
Ntinsky opened this issue Jun 6, 2024 · 0 comments
Open

Cannot update column data in Excel file #83

Ntinsky opened this issue Jun 6, 2024 · 0 comments

Comments

@Ntinsky
Copy link

Ntinsky commented Jun 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant