Solved

edit mobile phone number in office 365

Posted on 2016-10-21
15
36 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
Comment Utility
Have you changed the number from the Active Directory Users & Computers console instead ?
0
 
LVL 11

Author Comment

by:Ackles
Comment Utility
No, they were imported via excel
0
 
LVL 11

Author Comment

by:Ackles
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
DAMN.... it delete the mobile number completely
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 40

Expert Comment

by:Subsun
Comment Utility
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
Comment Utility
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
Comment Utility
:-) 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
Comment Utility
it gives error, A positional parameter cannot be found that accepts argument "abc@xyz.com"
0
 
LVL 40

Expert Comment

by:Subsun
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Awesome Stuff!!!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
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 …
how to add IIS SMTP to handle application/Scanner relays into office 365.
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…

772 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

14 Experts available now in Live!

Get 1:1 Help Now