Answer the question
In order to leave comments, you need to log in
Script not working in Powershell?
The script works only if the fields homephone and mobile have phones, but if at least one field is empty, then it does not work, can you somehow correct the regular expression or is it better to add if, else conditions?
Get-ADUser -SearchBase "DC=mydomain,DC=local" -Filter * -properties homephone, mobile | Foreach {
# ALL
$homephone = $_.homephone -replace "\D"
$mobile = $_.mobile -replace "\D"
# RU
$mobile = $mobile -replace '^8(\D{10})$ ','7$1'
$homephone = $homephone -replace '^8(\D{10})$','7$1'
Set-ADUser $_ -mobilephone $mobile -homephone $homephone
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question