Solved

edit mobile phone number in office 365

Posted on 2016-10-21
15
53 Views
Last Modified: 2016-10-21
Dear Experts,
I have a weird scenario, we imported lot of users in Office 365 (no dir sync) & after the import realised that many of the mobile phones are having a space in the number like: + 1 43 343 5433
The problem is with the space between + & 1st number only, rest of the space should be as it is, so the correct format would be: +1 43 343 5433

I would like to someone to help me with Powershell to find all users who have this space after + & then trim it.

I know I can export & then reimport with csv, but would prefer something with powershell so I can do it without csv.

Thanks in advance for your help!
Regards,
A
0
Comment
Question by:Ackles
  • 8
  • 6
15 Comments
 
LVL 7

Expert Comment

by:Senior IT System Engineer
ID: 41853759
Have you changed the number from the Active Directory Users & Computers console instead ?
0
 
LVL 11

Author Comment

by:Ackles
ID: 41853777
No, they were imported via excel
0
 
LVL 11

Author Comment

by:Ackles
ID: 41853818
I've found the regular expression as -Replace "(^\+(\s)1)", "+1"

This works to trim the space, but I have to make sure that I can get it to change the user mobile phone attribute.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41853953
If you have a list of users to update, you can use following code..
GC C:\User.txt | Get-User | %{Set-User $_.SamAccountName -MobilePhone ($_.MobilePhone -Replace "^\+\s+1","+1")}

Open in new window

User.txt format..
UserA
UserB
UserC

Open in new window

0
 
LVL 11

Author Comment

by:Ackles
ID: 41853960
Thanks,
I don't want to use the list...
Can it be directory done in powershell?
I can filter the users who's numbers are wrong

Get-MsolUser | where {$_.MobilePhone -Like "+ 1*"}  | ft DisplayName, MobilePhone -AutoSize
This shows all users who's numbers are not correct.

Question is how do I put this into variable to apply regex?
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41853966
Try..
Get-MsolUser | where {$_.MobilePhone -Like "+ 1*"}  | %{Set-MsolUser $_.SamAccountName -MobilePhone ($_.MobilePhone -Replace "^\+\s+1","+1")}

Open in new window

0
 
LVL 11

Author Comment

by:Ackles
ID: 41853975
DAMN.... it delete the mobile number completely
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 40

Expert Comment

by:Subsun
ID: 41853979
If should not delete if the Get-MsolUser | where {$_.MobilePhone -Like "+ 1*"}  | ft DisplayName, MobilePhone command lists the mobile number..
0
 
LVL 11

Author Comment

by:Ackles
ID: 41853986
well, i ran it for one user only because i didn't want to take risk, this is what I ran:

get-msoluser -UserPrincipalName abc@xyz.com | set-msoluser  -MobilePhone ($_.MobilePhone -Replace "^\+\s+1","+1")

After this command when i tried to see the value for user, it was empty for mobile phone
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41854002
:-) That will not work, because you are not using foreach command, so value of $_.MobilePhone would be null..

For single user try..
Get-msoluser -UserPrincipalName abc@xyz.com | %{Set-msoluser $_.UserPrincipalName -MobilePhone ($_.MobilePhone -Replace "^\+\s+1","+1")}

Open in new window

0
 
LVL 11

Author Comment

by:Ackles
ID: 41854007
it gives error, A positional parameter cannot be found that accepts argument "abc@xyz.com"
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41854011
Get-msoluser -UserPrincipalName abc@xyz.com | %{Set-msoluser -UserPrincipalName $_.UserPrincipalName -MobilePhone ($_.MobilePhone -Replace "^\+\s+1","+1")}

Open in new window

0
 
LVL 11

Author Comment

by:Ackles
ID: 41854016
Now it works!!!
Should I run the previous command you gave for all users or do you want to check?
Because it will run for all the users???
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41854021
Following should work..
Get-MsolUser | where {$_.MobilePhone -Like "+ 1*"}  | %{Set-msoluser -UserPrincipalName $_.UserPrincipalName -MobilePhone ($_.MobilePhone -Replace "^\+\s+1","+1")}

Open in new window

If you want to take a backup of MobilePhone details before you proceed, then you can use following command..
Get-MsolUser | where {$_.MobilePhone -Like "+ 1*"}  | Select UserPrincipalName,MobilePhone | Export-csv C:\report.csv -nti

Open in new window

0
 
LVL 11

Author Closing Comment

by:Ackles
ID: 41854036
Awesome Stuff!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A procedure for exporting installed hotfix details of remote computers using powershell
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now