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 (5)

  1. jrv says:

    @Ed – sounds like good clean fun.

    PowerShell is so easy for many of these sharp young techies to pick up.  They have been educated in an OOP world which may have something to do with it.

    It is also a fun game to play.  

  2. jrv says:

    Yes – splatting is definitely underappreciated.  It can greatly simply and make scripts more readable.

  3. Ed Wilson says:

    @JRV indeed. It was actually pretty funny, they were working on the script, and I gave suggestions, then someone else came along and gave suggestions … it was a real-time collaboration, and the first time I have seen PowerShell as a Spectator Sport!

  4. Mark Latham says:

    Does anybody have a suggestion for AD Health script for admins to run daily but not have the output be volumes worth?