{"id":3498,"date":"2013-06-03T08:31:00","date_gmt":"2013-06-03T08:31:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/06\/03\/teched-2013-a-couple-of-scripts\/"},"modified":"2013-06-03T08:31:00","modified_gmt":"2013-06-03T08:31:00","slug":"teched-2013-a-couple-of-scripts","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/teched-2013-a-couple-of-scripts\/","title":{"rendered":"TechEd 2013: A Couple of Scripts"},"content":{"rendered":"<p><strong>Summary<\/strong>: A couple of quick Active Directory scripts from the Scripting Guys booth.<\/p>\n<p>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.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3005.BrianMikeChris_61DB4C19.png\"><img decoding=\"async\" style=\"border: 0px currentcolor;padding-top: 0px;padding-right: 0px;padding-left: 0px\" title=\"BrianMikeChris\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7217.BrianMikeChris_thumb_64A1010C.png\" alt=\"BrianMikeChris\" width=\"244\" height=\"167\" border=\"0\" \/><\/a><\/p>\n<p>So what did they come up with? Here is the first script:<\/p>\n<p><span style=\"text-decoration: underline\">Create AD Organizational Unit and 10 users<\/span><\/p>\n<p>$NewOUSplat = @{ <br \/>&nbsp;&nbsp;&nbsp; Name=&#8221;TechEd2013&#8243; <br \/>&nbsp;&nbsp;&nbsp; Description=&#8221;MyScript&#8221; <br \/>&nbsp;&nbsp;&nbsp; Path=&#8221;DC=NWTraders,DC=COM&#8221; <br \/>&nbsp;&nbsp;&nbsp; } <br \/>New-ADOrganizationalUnit @NewOUSplat<\/p>\n<p>for ($i=1;$i -le 10;$i++) { <br \/>&nbsp;&nbsp;&nbsp; $NewUserSplat = @{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SamAccountName=&#8221;User$i&#8221; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name=&#8221;User$i&#8221; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Path=&#8221;OU=TechEd2013,DC=NWTraders,DC=COM&#8221; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br \/>&nbsp;&nbsp;&nbsp; New-ADUser @NewUserSplat <br \/>&nbsp;&nbsp;&nbsp; }<\/p>\n<p>Get-ADUser -Filter * -SearchBase &#8220;OU=TechEd2013,DC=NWTraders,DC=COM&#8221; |<\/p>\n<p>select SamAccountName<\/p>\n<p>&nbsp;<\/p>\n<p>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&#8217;s the cleanup script:<\/p>\n<p><span style=\"text-decoration: underline\">Remove AD Organizational Unit and users<\/span><\/p>\n<p>Get-ADOrganizationalUnit -Filter {Name -eq &#8220;Teched2013&#8221;} | <br \/>&nbsp;&nbsp;&nbsp; Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion:$false -PassThru | <br \/>&nbsp;&nbsp;&nbsp; Remove-ADOrganizationalUnit -Recursive -Confirm:$false<\/p>\n<p>It looks like they are getting ready to open the doors. I will keep you updated with the &#8220;goings-on&#8221; here as time permits. Have an absolutely great day!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[7,3,428,247],"class_list":["post-3498","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-scripting-guy","tag-teched","tag-writing-scripts"],"acf":[],"blog_post_summary":"<p>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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=3498"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3498\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=3498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}