Link to home
Start Free TrialLog in
Avatar of MilesLogan
MilesLoganFlag for United States of America

asked on

Copy Description data to info field for multiple active directory accounts

HI EE

I am needing to copy the data in the Description field to the info field ..
Trying to recycle and other scripts but I can't seem to get it .. below is as far as I got but I get no results or errors .

$users = import-csv .\CopytoTel.txt
ForEach ($user in $users) {
$Description = (Get-ADUser $user -Properties Description)
Set-ADUser $user -replace @{info="$Description `r`n$Description"}
}
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

assuming copytotel.txt is
users,Description
username1,This is the description

$users = import-csv C:\users\Administrator\Documents\copytoTel.csv
ForEach ($user in $users) {
write-host ("Username is: {0} Description is {1}" -f $user.users, $user.description)
$Description = (Get-ADUser $user.users -Properties Description) | select description
$description
Set-ADUser $user.users -replace @{info="$Description `r`n$Description"}
}
#
# if just a list of usernames
#
$users = Get-Content C:\users\Administrator\Documents\copytoTel.txt
ForEach ($user in $users) {
write-host ("Username is: {0}" -f $user)
$Description = (Get-ADUser $user -Properties Description) 
Set-ADUser $user -replace @{info="$Description `r`n$Description"}
}

get-aduser -Filter * | select samaccountname,description

Open in new window

What are you really trying to do?
Avatar of MilesLogan

ASKER

thank u , I will test ..
 
I need to copy the information in the description field to the telephone tab " info " field

not for all users , just a couple thousand
Hi David

Neither option had the result I need .

script 1) it deleted what was in the Notes "info" field and it entered two lines with @[description=testdata}
 testdata is what is in the description field of my test account , not what was entered in the csv file .

script2) which is the option I rather use, deleted what was in the Notes "info" field and it entered the test account DN two times .


I need to copy from a list of users what is in the description to the Notes "info" field as a new line , leaving what is already there .
thank you !
I guess "$Description `r`n$Description" is an error, as you most probably do not want to copy the description twice.
And you didn't answer the (implicit) question about the CSV format. I assume it is just the name, without any column header?
$users = Get-Content .\CopytoTel.txt
ForEach ($user in $users) {
  $Description = (Get-ADUser $user -Properties Description).Description
  if ($Description) { Set-ADUser $user -replace @{info=$Description} }
}

Open in new window

or more PowerShellish. as I would do:
Get-Content .\CopytoTel.txt |
  Get-ADUser -Properties Description |
  ? { $_.Description } |
  % {  Set-ADUser $_  -Replace @{info=$_.Description} }

Open in new window

Note that you have to make sure Description is not empty, othewise Set-ADUser will throw an error. I've added checks to both scripts.
Hi Qlemo

both of these work but delete the data that is already in the info field , I need to keep the data that is already there .
what I can modify to keep the data in the info field ?

If I can get your options to work , I don't need the CSV option ..
the CSV option would be SamAccountName,Description but if your options work , I don't need to pull the data and then update through a CSV ,
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Qlemo

This did exactly what I needed .. thank you so much for your help .. Happy Holidays