?
Solved

edit mobile phone number in office 365

Posted on 2016-10-21
15
Medium Priority
?
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
15 Comments
 
LVL 8

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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

After hours on line I found a solution which pointed to the inherited Active Directory permissions . You have to give/allow permissions to the "Exchange trusted subsystem" for the user in the Active Directory...
New style of hardware planning for Microsoft Exchange server.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Suggested Courses

765 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