πŸ“΅ Powershell: Updating Users, Mobile numbers in bulk

This will get the users UPN from a CSV file in the location is variable csvFilePath (in bold) the format of the CSV needs to be UPN,MobileNumber like this:


WARNING: Please do not just run scripts from the internet without checking them and ensuring you know what they are doing, this could break you domain or user logins, this script will write/change attributes to your domain


Then this is the script to make the magic happen:

# Define the path to the CSV file
$csvFilePath = "C:\path\to\user_mobile_numbers.csv"

# Import the Active Directory module
Import-Module ActiveDirectory

# Read the CSV file
$csvData = Import-Csv -Path $csvFilePath

# Loop through each row in the CSV and update the mobile number
foreach ($row in $csvData) {
   $username = $row.Username
    $newMobileNumber = $row.MobileNumber

    # Try to find the user in Active Directory

    $user = Get-ADUser -Filter {SamAccountName -eq $username}

    if ($user) {

        # Update the mobile number
        Set-ADUser -Identity $user -Replace @{mobile=$newMobileNumber}
        Write-Host "Updated mobile number for $($user.SamAccountName) to $newMobileNumber"
    } else {

        Write-Host "User $username not found in Active Directory."

    }

}


Previous Post Next Post

Ω†Ω…ΩˆΨ°Ψ¬ Ψ§Ω„Ψ§ΨͺΨ΅Ψ§Ω„