TechEd 2013: A Couple of Scripts

TechEd 2013: A Couple of Scripts

  • Comments 5
  • Likes

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.

BrianMikeChris

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

Create AD Organizational Unit and 10 users

$NewOUSplat = @{
    Name="TechEd2013"
    Description="MyScript"
    Path="DC=NWTraders,DC=COM"
    }
New-ADOrganizationalUnit @NewOUSplat

for ($i=1;$i -le 10;$i++) {
    $NewUserSplat = @{
        SamAccountName="User$i"
        Name="User$i"
        Path="OU=TechEd2013,DC=NWTraders,DC=COM"
        }
    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!

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Yes - splatting is definitely underappreciated.  It can greatly simply and make scripts more readable.

  • @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!

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

  • @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.  

  • thanks