Weekly Tip 58

You can use this script to mass create sequentially named computer objects in AD. This is helpful if you pre-stage object before imaging, and they are all named with a common scheme. This script requires the AD PowerShell module. The first variable ($number) should be one less than the starting number, meaning that if your first machine is ABC-01, this variable should equal zero. Second, input your naming scheme on the line that starts with $name. Change the OU path on the new-adcomputer line to reflect the location where the objects should be created. Finally, change the “Until” line to be the last machine, meaning that if I want 1 – 25 created, I would make this line ABC-25.

Import-Module activedirectory

$number = 0

Do {
$number = $number + 1
If ($number -lt 10) {$name = “ABC-0” + “$number”} Else {$name = “ABC-” + “$number”}
new-adcomputer -name $name -SAMAccountName $name -path “ou=accounting,ou=computers,dc=contoso,dc=com”
write-host “created $name”
} Until ($name -eq “ABC-25”)

Share:

Facebook
Twitter
LinkedIn
Picture of Matt Tinney

Matt Tinney

Professional IT executive & business leader having decades of experience with Microsoft technologies delivering modern-day cloud & security solutions.

Contact Us

=
On Key

More Posts

WME Cybersecurity Briefings No. 024
Cyber Security

WME Security Briefing 28 August 2024

GhostWrite Vulnerability in T-Head CPUs Exposes Devices to Unrestricted Access Overview A critical architectural flaw in T-Head’s XuanTie C910 and C920 RISC-V CPUs was uncovered by recent research from the CISPA Helmholtz Center for Information Security. Dubbed GhostWrite, the vulnerability

Click Here to Read Full Article »
Be assured of everything

Get WME Services

Stay ahead of the competition with our Professional IT offerings.

=