Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Edit phone number in AD with Powershell?

$
0
0

Hi.

I need to correct 3 AD-attributes in AD for all users so that the numbers will be without spaces and the country code +45 needs to be added on:

a) HomePhone

b) MobilePhone

c) OtherMobile

 

Example:

Before:

Homephone: xx xx xx xx

MobilePhone: +45 xx xx xx xx

OtherMobile: xxxx xxxx

Wanted result:

Homephone: +45xxxxxxxx

MobilePhone: +45xxxxxxxx

OtherMobile: +45xxxxxxxx

I have tried various things but cannot get it right:

get-aduser -SearchBase "OU=NoAdm,OU=Users,DC=xxxxx,DC=xxxxx,DC=xxxxx,DC=net" -filter * -properties homephone | where { $_.Homephone -ne $_.Homephone.trim() }

I have also tried various commands with -replace '\s+',""

I would appreciate a helping hand! Smile


Viewing all articles
Browse latest Browse all 6937

Trending Articles