TechEd 2013: A Couple of Scripts

Summary: A couple of quick Active Directory scripts from the Scripting Guys booth.

This morning Brian Wilhite, Chris Duck, and Mike Robbins were playing around with Windows PowerShell. They decided to create a couple of scripts. The first script creates an organizational unit and ten users in the organizational unit. Here are Chris, Mike and Brian as they work on the script.


So what did they come up with? Here is the first script:

Create AD Organizational Unit and 10 users

$NewOUSplat = @{
New-ADOrganizationalUnit @NewOUSplat

for ($i=1;$i -le 10;$i++) {
    $NewUserSplat = @{
    New-ADUser @NewUserSplat

Get-ADUser -Filter * -SearchBase “OU=TechEd2013,DC=NWTraders,DC=COM” |

select SamAccountName


Here is the second script that performs the cleanup. One of my fundamental rules is that if a script creates something, I should also write the script so that it will delete that same something. So here’s the cleanup script:

Remove AD Organizational Unit and users

Get-ADOrganizationalUnit -Filter {Name -eq “Teched2013”} |
    Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion:$false -PassThru |
    Remove-ADOrganizationalUnit -Recursive -Confirm:$false

It looks like they are getting ready to open the doors. I will keep you updated with the “goings-on” here as time permits. Have an absolutely great day!


Comments are closed. Login to edit/delete your existing comments