Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

TechEd 2013: A Couple of Scripts

$
0
0

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

Well 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

Well, 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!


Viewing all articles
Browse latest Browse all 3333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>