politicnewsbusterinsiderpostreview

▼

Wednesday, 19 October 2022

[New post] Exchange 2019 / Active Directory :- Update mobile numbers using PowerShell

Site logo image Edward van Biljon posted: " I was tasked with updating a number of mobile numbers in Active Directory and the easiest way that this was accomplished was by using a CSV file and PowerShell. The CSV consisted of two columns. One for the UPN and another for the mobile number. Wi" Everything-PowerShell

Exchange 2019 / Active Directory :- Update mobile numbers using PowerShell

Edward van Biljon

Oct 19

I was tasked with updating a number of mobile numbers in Active Directory and the easiest way that this was accomplished was by using a CSV file and PowerShell.

The CSV consisted of two columns. One for the UPN and another for the mobile number.

With any script, I normally use the -WhatIf statement. On line 9, between the two curly brackets ( } -WhatIf } ) you can put the statement in and this will give you an output of what is being changed.

In the figure below, this is the code used and I have provided it at the end of the article in text format for you to use. Just copy it to notepad and save it as a .PS1 file.

$Users = Import-Csv "C:\Temp\Numbers.csv"    foreach ($u in $Users) {    $Staff = Get-aduser -Server mydc.domain.com -filter "UserprincipalName -eq '$($u.upn)'" -Properties samaccountname,UserprincipalName | select samaccountname,UserprincipalName    foreach ($s in $Staff){     Set-ADUser -Identity $s.samaccountname -Replace @{mobile = $($u.mobile)} }    }   

Let's go over what the script does.

$Users = this is a variable to import the CSV file. The CSV file has a column called UPN and mobile and this is mapped in the lines with $u.
$Staff = this is another variable that queries Active Directory (note this was run from a DC, so no modules were imported)
The set command uses a replace option (-Replace) to either update an existing number and if nothing exists then the number is simply added.

Hope it helps.

Comment

Unsubscribe to no longer receive posts from Everything-PowerShell.
Change your email settings at manage subscriptions.

Trouble clicking? Copy and paste this URL into your browser:
https://everything-powershell.com/exchange-2019-active-directory-update-mobile-numbers-using-powershell/

Powered by Jetpack
Download on the App Store Get it on Google Play
at October 19, 2022
Share

No comments:

Post a Comment

‹
›
Home
View web version

About Me

politicnewsbusterinsiderpostreview
View my complete profile
Powered by Blogger.