Forum Discussion
Update telephone notes in AD with powershell
Hi AresWare,
I'm assuming that your CSV file contains two headers: User and Answer. Your first line will import the the CSV file into the Variable $UserNamesCSV.
The variable will automatically be created as an array with User and Answer. So, each line of $UserNamesCSV will contain a user with its corresponding Answer. Therefor there's no need for the $usersplit variable to be created. You can check that by calling $UserNamesCSV[0] which will show the very first line of the variable. $UserNamesCSV[1] will show the second line and so fort. Therefor you only need to loop through all the lines of $UserNamesCSV with the foreach statement to set the corresponding values.
The script would end up looking like this:
$UserNamesCSV = Import-CSV 'C:\temp\users.csv' -Delimiter ","
foreach($user in $UserNamesCSV){
Set-ADuser -identity $user.user -replace @{info=$user.answer}
}
Let me know if that doesn't work.
Regards,
Ruud
- RGijsbersRademakersFeb 10, 2023Iron Contributor
Hi AresWare,
I'm not sure how to get them al underneath each other, but you could try the following like in your starting post:
$UserNamesCSV = Import-CSV 'C:\temp\users.csv' -Delimiter "," foreach($user in $UserNamesCSV){ $usersplit = $user.answer -split ';' | Out-String Set-ADuser -identity $user.user -replace @{info=$usersplit} }
Regards,
Ruud