Solved

edit mobile phone number in office 365

Posted on 2016-10-21
15
72 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

790 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