none
Powershell Script to copy mobilephone number to telephone number RRS feed

  • Question

  • Hello Friends,

    I need a powershell script to copy mobilephone attribute to telephone attribute.

    Scenario is below:

    I have Group "Test1" , I need to copy mobilephone attribute to telephone attribute of all the uses in this Group.

    I have created the script but its not giving desired result

    "Get-QADGroup "test1"| ForEach-Object{ Get-QADGroupMember$_.samaccountname}| selectsamaccountname,mobilephone | export-csvD:\test1.csv

    Import-Csv "D:\test1.csv"| %{Get-QADUSer$_.Samaccountname | Set-QADUser-ObjectAttributes@{telephonenumber=$_.mobilephone}}"

    My observation:

    1.while I exporting the attribute , i am not getting proper telephone format in CSV which is "+919999XXX1111" 

    2. If Telephonenumber attribute of a user is allready filled , it does not update the attribute. it only update the attribute if it is blank

    Plase help to resolve it.

    this is kind of urgent , thank you all in advance


     

    Wednesday, October 1, 2014 7:57 AM

Answers

  • Glad that it worked. Cheers!!!

    Regards Chen V [MCTS SharePoint 2010]


    • Edited by Chen VMVP Wednesday, October 1, 2014 2:01 PM
    • Marked as answer by STscripter Thursday, October 30, 2014 1:07 PM
    Wednesday, October 1, 2014 2:01 PM

All replies

  • Try this

    Import-Module ActiveDirectory -Erroraction Silentlycontinue
    Import-Csv "D:\test1.csv" | %{Set-ADUser -Identity $_.samaccountname -OfficePhone $_.mobilephone}


    Regards Chen V [MCTS SharePoint 2010]

    • Proposed as answer by Mike Laughlin Wednesday, October 1, 2014 1:56 PM
    Wednesday, October 1, 2014 8:14 AM
  • Thank you for your reply

    but it is not changing anything however scripts executes perfectly.

    I want to add one more thing here when i export the "mobilePhone" attribute it comes in the format "9.2E+11"

    whereas it should come in the format "+919999XXX111".

    So, as i said earlier if "telephonenumber" fields remains blank it takes the value "9.2E+11" which is error. but it is not replacing if fileld has some value and value format is not correct.

    Wednesday, October 1, 2014 9:29 AM
  • Check your CSV file it shud have incorrect format in the cell. So script is updating the same.

    Fix the CSV format by removing the " character and run the script.


    Regards Chen V [MCTS SharePoint 2010]


    • Edited by Chen VMVP Wednesday, October 1, 2014 9:55 AM
    Wednesday, October 1, 2014 9:53 AM
  • thnaks

    resolved  :)

    Wednesday, October 1, 2014 1:54 PM
  • Glad that it worked. Cheers!!!

    Regards Chen V [MCTS SharePoint 2010]


    • Edited by Chen VMVP Wednesday, October 1, 2014 2:01 PM
    • Marked as answer by STscripter Thursday, October 30, 2014 1:07 PM
    Wednesday, October 1, 2014 2:01 PM