Post

Handy Scripts

Handy Scripts

Script to set phone number on all users in the acme lab

This script sets the phone number for all the users in the ACME lab. Run the script on DC01. Once completed your phone number will be updated on Active-Directory acocunts.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Ensure the Active Directory module is imported
Import-Module ActiveDirectory

# Prompt user for a mobile/cell number
$StudentMobile = Read-Host "Enter your Mobile/Cell number (e.g., +614xxxxxxxx)"

# Define users and assign the mobile number.
$users = @(
    @{ Name = "mike"},
    @{ Name = "carlos"},
    @{ Name = "cindy"},
    @{ Name = "tom"},
    @{ Name = "john"},
    @{ Name = "paul"}
)

# Update mobile number for each user
foreach ($user in $users) {
    try {
        Set-ADUser -Identity $user.Name -MobilePhone $StudentMobile
        Write-Host "Updated mobile number for $($user.Name) to $StudentMobile"
    } catch {
        Write-Warning "Failed to update mobile number for $($user.Name): $_"
    }
}
This post is licensed under CC BY 4.0 by the author.