Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

edit mobile phone number in office 365

Posted on 2016-10-21
15
Medium Priority
?
281 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

618 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