06-07-2017 02:42 AM
Hi
I need to move data from one attribute to another on a user object in Active Dirctory.
Today the attribute homePhone is porpulated with users private mobile number. I need to move this to otherMobile.
First I try to do this on my own account this way:
$homePhone = get-aduser -identity INITIALS -Properties * | Select-Object homePhone
Then I want to copy from homePhone to otherMobile this way:
set-aduser -identity INITIALS -add @{otherMobile='$homePhone')
This sort of works. In my otherMobile is now: {otherMobile='+45XXXXXXXX')
How can I only put in the value $homePhone and not the whole string?
Of course in the end the script should find all users with the homePhone porpulated and copy the value to otherMobile...
06-07-2017 04:29 AM
Please use the below script and check.
$users = get-aduser -Filter * -Properties *|Where-Object {$_.homePhone -ne $null }| Select-Object Samaccountname,homePhone foreach($user in $users) { set-aduser -identity $user.Samaccountname -add @{otherMobile=$user.homephone} }
06-08-2017 01:31 AM
Hi.
That works fine. But I made a little error, it was the attribute otherhomePhone and not homePhone. When I replace homePhone with otherhomePhone, it does not work any more.
Can you tell me why?
06-08-2017 02:29 AM - edited 06-08-2017 02:39 AM
06-08-2017 02:29 AM - edited 06-08-2017 02:39 AM
SolutionHi
Otherhomephone is multivalue attribute so that it is not working and you can try below script
$users = get-aduser -Filter * -Properties *|Where-Object {$_.otherhomePhone -ne $null }| Select-Object Samaccountname,otherhomePhone
foreach($user in $users)
{
if($user.otherhomePhone.count -gt 1)
{
foreach($hph in $user.otherhomePhone)
{
set-aduser -identity $user.Samaccountname -add @{otherMobile=$hph}
}
}
else
{
set-aduser -identity $user.Samaccountname -add @{otherMobile=$user.otherhomePhone[0]}
}
}