Forum Discussion
AresWare
Feb 03, 2023Copper Contributor
Update telephone notes in AD with powershell
Hello! I'm a beginner to PowerShell and I created this script which mostly works. It does a line break in between semicolons however it doesn't follow by row it updates every user in the csv with the...
RGijsbersRademakers
Feb 03, 2023Iron Contributor
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
- AresWareFeb 06, 2023Copper ContributorThis is great! However I need a line break in between. For instance my cell would look like. Hi;hi2;hi3 and I’d like them to be under each other.
- 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