• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3455
  • Last Modified:

modify serveral AD user officephone attribute via powershell

hello experts
“officephone" attribute is not correct in our AD information, so need to update all of them to correct, i have already export a CSV file via get-aduser command, so row A in the file is username or email address, also i have done update the file in row B with their phone number correspond everyone.
my question is which command i should using on powershell to update all users base on the updated CSV file.

thank you
0
beardog1113
Asked:
beardog1113
  • 17
  • 16
1 Solution
 
Krzysztof PytkoActive Directory EngineerCommented:
You can try this way

Import-Module ActiveDirectory
Import-CSV c:\users.csv | %{
Get-ADUser $_."HeaderForColumnA" | Set-ADUser -OfficePhone $_."HeaderForColumnB"
}

Open in new window


and this should work. If you could, please post an example CSV file with some fake data and I will give you full solution adjusted to your CSV file :)

Regards,
Krzysztof
0
 
beardog1113Author Commented:
hello  iSiek
thanks for your reply, check attach please, and kindly provide solution please.

thank you
user.csv
0
 
Krzysztof PytkoActive Directory EngineerCommented:
OK, phone number columns cannot be with space, so please use

email,phoneNumber

headers and run below code

Import-Module ActiveDirectory
Import-CSV c:\users.csv | %{
Get-ADUser -Filter {Mail -eq $_."email"} | Set-ADUser -OfficePhone $_."phoneNumber"
}

Open in new window


Krzysztof
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
beardog1113Author Commented:
hello,  iSiek
i got the following error, anything wrong with command? and any ideas?
thank you

PS C:\Users\ad-fan.meng>Import-Module ActiveDirectory
PS C:\Users\ad-fan.meng>Import-CSV c:\users.csv | %{
>>Get-ADUser -Filter {Mail -eq $_."email"} | Set-ADUser -OfficePhone $_."phoneNumber"
>>}
>>}
>>
Unexpected token '}' in expression or statement.
At line:4 char:2
+ } <<<<
    + CategoryInfo          : ParserError: (}:String) [], ParentContainsErrorR
   ecordException
    + FullyQualifiedErrorId : UnexpectedToken
0
 
Krzysztof PytkoActive Directory EngineerCommented:
To much "}" characters. Remove the last one from the syntax :)

Krzysztof
0
 
beardog1113Author Commented:
hello iSiek
but it stopped there >>
what can i do next?
thank you

PS C:\Users\ad-fan.meng>Import-Module ActiveDirectory
PS C:\Users\ad-fan.meng>Import-CSV c:\users.csv | %{
>>Get-ADUser -Filter {Mail -eq $_."email"} | Set-ADUser -OfficePhone $_."phoneNumber"
>>}
>>
0
 
Krzysztof PytkoActive Directory EngineerCommented:
OK, try to download this script and copy code from it or execute it directly :) (remove .txt from its extension)

upd.ps1.txt

Krzysztof
0
 
beardog1113Author Commented:
cool, this one works

Import-Module ActiveDirectory
Import-CSV c:\users.csv | %{
$usrmail=$_."email"
Get-ADUser -Filter { mail -eq $usrmail } | Set-ADUser -OfficePhone $_."phoneNumber"
$usrmail=""
}
0
 
beardog1113Author Commented:
fixed, thx
0
 
Krzysztof PytkoActive Directory EngineerCommented:
Great! You're welcome :)

Krzysztof
0
 
beardog1113Author Commented:
hi iSiek
may i have another request?
i want to learn what is
$
%
{}
$_.
meaning, any document i can read?

thanks
0
 
Krzysztof PytkoActive Directory EngineerCommented:
Sure :)

$ - define that this is variable
$_ - means current value from pipe
$_."property" - current variable from pipe and its pointed property
% - mean ForEach, it's short cut (kind of loop)
{ - begin
} - end (for block commands processing

Check Chris-Dent about on his profile
http://www.experts-exchange.com/M_3452732.html

and you will find there some books for start about power shell. One is even free and I started from it :)

Krzysztof
0
 
beardog1113Author Commented:
that's great, you help and teach me so much today.
nice weekend
0
 
Krzysztof PytkoActive Directory EngineerCommented:
I'm glad I could help.
Have a nice weekend too

Krzysztof
0
 
beardog1113Author Commented:
hello iSiek
a question related question about this, i am also manage a 2003 domain, does it possible manage 2003 domain via powershell?
i have install powershell 2.0 on a windows 2003 domain controller, but it seem not such as "get-aduser" command, while i am trying import-module activedirectory, it said not such module found.
if you know about it i can raise another question and leave it to be answer by you:)

thanks
0
 
Krzysztof PytkoActive Directory EngineerCommented:
No, this AD cmd-lets are available only on Windows Server 2008R2 when AD Web services are running.

However, you can do that using PowerShell on 2008r2 or Windows 7

To be able to use directly on 2003, you need to download free Quest PowerShell module for AD from http://www.quest.com/powershell/activeroles-server.aspx

but syntax is a little bit different, all cmd-lets are with Q letter :)

Krzysztof
0
 
beardog1113Author Commented:
ok thanks, that looks perfect, let me have it installed first and have a look, i may raise another question about this, also i may need your help about cmd-lets:)

btw, which EE zone your are primary response?

nice day
0
 
Krzysztof PytkoActive Directory EngineerCommented:
No problem, you're welcome :) and I hope I would be able to help further too ;)
I'm mostly on Active Directory but I would also check Windows Server 2003 and 2008

Krzysztof
0
 
beardog1113Author Commented:
hello  iSiek
another question about this under 2003 is submitted, help me on this please.

thank you

http://www.experts-exchange.com/Software/Server_Software/File_Servers/Active_Directory/Q_27861758.html
0
 
Krzysztof PytkoActive Directory EngineerCommented:
OK, I'm on your new thread :)

Krzysztof
0
 
beardog1113Author Commented:
hello iSiek
i am got the following error for some users, others is fine, they all in same CSV file.
any ideas about this?

thank you

PS C:\Windows\system32> import-csv d:\test.csv | %{
>>  $usrmail=$_."email"
>> Get-ADUser -Filter {mail -eq $usrmail} | Set-ADUser -OfficePhone $_."phone" -MobilePhone $_."mobil"
>> $usrmail=""
>> }
>>
Set-ADUser : replace
At line:3 char:52
+ Get-ADUser -Filter {mail -eq $usrmail} | Set-ADUser <<<<  -OfficePhone $_."phone" -MobilePhone $_."mobil"
    + CategoryInfo          : InvalidOperation: (CN=Ye Liao,OU=U...DC=ipsos,DC=com:ADUser) [Set-ADUser], ADInvalidOper
   ationException
    + FullyQualifiedErrorId : replace,Microsoft.ActiveDirectory.Management.Commands.SetADUser

Set-ADUser : replace
At line:3 char:52
+ Get-ADUser -Filter {mail -eq $usrmail} | Set-ADUser <<<<  -OfficePhone $_."phone" -MobilePhone $_."mobil"
    + CategoryInfo          : InvalidOperation: (CN=Lea Deng,OU=...DC=ipsos,DC=com:ADUser) [Set-ADUser], ADInvalidOper
   ationException
    + FullyQualifiedErrorId : replace,Microsoft.ActiveDirectory.Management.Commands.SetADUser

Set-ADUser : replace
At line:3 char:52
+ Get-ADUser -Filter {mail -eq $usrmail} | Set-ADUser <<<<  -OfficePhone $_."phone" -MobilePhone $_."mobil"
    + CategoryInfo          : InvalidOperation: (CN=Jeremy Hou,O...DC=ipsos,DC=com:ADUser) [Set-ADUser], ADInvalidOper
   ationException
    + FullyQualifiedErrorId : replace,Microsoft.ActiveDirectory.Management.Commands.SetADUser

Set-ADUser : replace
At line:3 char:52
+ Get-ADUser -Filter {mail -eq $usrmail} | Set-ADUser <<<<  -OfficePhone $_."phone" -MobilePhone $_."mobil"
    + CategoryInfo          : InvalidOperation: (CN=Isabelle Che...DC=ipsos,DC=com:ADUser) [Set-ADUser], ADInvalidOper
   ationException
    + FullyQualifiedErrorId : replace,Microsoft.ActiveDirectory.Management.Commands.SetADUser
0
 
Krzysztof PytkoActive Directory EngineerCommented:
Hello,

looks like an issue with FQDN + FullyQualifiedErrorId : replace,Microsoft.ActiveDirectory.Management.Commands.SetADUser

and distinguished name of a user in not accepted. Do you have more that one domain in your environment ? If so, that might be an issue. Users have common DNS domain name for e-mail but their domain accounts are from different domains.

Can you confirm that, please ?

Krzysztof
0
 
beardog1113Author Commented:
hello
yes, i have another 2003 domain, all email servers in 2003 domain, for 2008 domain user accounts, they have a linked account in 2003, so that their email could working

thank you
0
 
Krzysztof PytkoActive Directory EngineerCommented:
So, you need to separate those account from current CSV file and put them into another one. Then you need to run updates in separate domains

Krzysztof
0
 
beardog1113Author Commented:
hello iSiek
all account i am wondering to modify are same in the CSV file, they all 2008 domain account users, and they all have email address attribute. actually there is hundreds of accounts in the CSV file, and only these four account display this error, all others are fine.

for these four account i can got their info via:  Get-ADUser -Filter {mail -eq "email address"} command,
also i can modify their info via Get-ADUser -Filter {mail -eq "email address"} | Set-ADUser -OfficePhone "11111111" command one by one
but only it doesn't work if they are in CSV file, although i have tried put them into a new CSV file.

for these only four users, i can change it one by one manually, i am just circus why it happened, so that i can learn more :)

thank you
0
 
Krzysztof PytkoActive Directory EngineerCommented:
OK, can you show me that CSV file for these 4 users only, please ? Maybe some characters issue ?

Thank you in advance

Krzysztof
0
 
beardog1113Author Commented:
check attach please

thank you and i don't think i am so stupid under characters issue :)
test.csv
0
 
Krzysztof PytkoActive Directory EngineerCommented:
OK, I've got it. Now, I will try to figure out what is causing the issue :)
I did not mean that you are stupid and made a mistake with character :] sometimes due to file save format some strange issues happens :/

Krzysztof
0
 
Krzysztof PytkoActive Directory EngineerCommented:
OK, as I can see, you want to modify only phone number for these users, right ? Set-QADUser expects another variable (mobile) but it is empty. You need to place something there too :)

Krzysztof
0
 
beardog1113Author Commented:
hello iSiek
you are correct if you not update "mobilphone" or put some digital value into "mobil" column no error again, strange this is lots of users in the CSV which "mobile" is blank but only these four doesn't work, any way lets ignore it.

and may i have the last question about this topic? i promise :)
what is $usrmail="" meaning in your command, sorry i forgot ask this one last time.

thank you very much
0
 
Krzysztof PytkoActive Directory EngineerCommented:
Hello,

yes, that's strange :/

No problem, if you need help, just ask ;)

$usrmail is a variable. We are using it to assign some value to it. It is good to clear previous value before you add another. Just in case, it is better to have blank variable before next use.

So, $usrmail="" menas - clear value of that variable

Krzysztof
0
 
beardog1113Author Commented:
thank you, my professional, my teacher. :)
0
 
Krzysztof PytkoActive Directory EngineerCommented:
No problem, you're welcome :)
Ask when you need help

Krzysztof
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 17
  • 16
Tackle projects and never again get stuck behind a technical roadblock.
Join Now