{"id":51483,"date":"2010-01-26T00:01:00","date_gmt":"2010-01-26T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/01\/26\/hey-scripting-guy-how-can-i-create-users-and-organizational-units-with-active-directory-domain-services-cmdlets\/"},"modified":"2010-01-26T00:01:00","modified_gmt":"2010-01-26T00:01:00","slug":"hey-scripting-guy-how-can-i-create-users-and-organizational-units-with-active-directory-domain-services-cmdlets","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-create-users-and-organizational-units-with-active-directory-domain-services-cmdlets\/","title":{"rendered":"Hey, Scripting Guy! How Can I Create Users and Organizational Units with Active Directory Domain Services Cmdlets?"},"content":{"rendered":"<p><a class=\"addthis_button\" href=\"http:\/\/www.addthis.com\/bookmark.php?v=250&amp;pub=scriptingguys\"><img decoding=\"async\" alt=\"Bookmark and Share\" src=\"http:\/\/s7.addthis.com\/static\/btn\/v2\/lg-share-en.gif\" width=\"125\" height=\"16\"><\/a><\/p>\n<p>&nbsp;\n<img decoding=\"async\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"><\/p>\n<p class=\"MsoNormal\">Hey, Scripting Guy! I am interested in using Active Directory Domain Services (AD DS) cmdlets to create users and organizational units. Is this a hard thing to do? I only ask this because I am an extremely busy network administrator who has barely had time to begin looking at Windows PowerShell. I do not have a lot of time to spend learning a bunch of cryptic commands. If it is really hard, I will need to take a pass on the information right now. <\/p>\n<p class=\"MsoNormal\">&#8212; DA<\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\">Hello DA, <\/p>\n<p class=\"MsoNormal\">Microsoft Scripting Guy Ed Wilson here. I have thirty minutes before my one-on-one meeting with the Scripting Manager. Having a one-on-one with Steve is always the highlight of my day because he is funny, intelligent, and extremely passionate about the TechNet Script Center. I always emerge from our meetings with lots of ideas for new things to try. As an added bonus, Steve is also a writer who has written several certification books; therefore, he understands the writing process in a very real and personal manner. Before my meeting with Steve, I thought I would check the e-mail in the <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a> inbox, send out a few tweets on Twitter, make a fresh pot of Earl Gray tea, and crank up Pink Floyd on my Zune HD. <\/p>\n<p class=\"MsoNormal\">Now that I am mentally and physically set for my one-on-one, let me get prepared for the meeting. I know he will ask about the 2010 Scripting Games. So how are we doing there? <\/p>\n<p class=\"MsoNormal\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>I spent much of yesterday creating three events for the 2010 Scripting Games. <\/p>\n<p class=\"MsoNormal\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>We have a theme picked out: The Winter Olympics.<\/p>\n<p class=\"MsoNormal\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>We have 10 event themes selected.<\/p>\n<p class=\"MsoNormal\">He will also ask about the new Weekend Scripter series. <\/p>\n<p class=\"MsoNormal\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>Weekend Scripter starts on Saturday February 6, 2010, when we begin publishing seven days a week. (See? We really do love this stuff.)<\/p>\n<p class=\"MsoNormal\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>The first Weekend Scripter blog post will be about writing a Windows PowerShell function to determine the volume of a space.<\/p>\n<p class=\"MsoNormal\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>The second Weekend Scripter blog post (February 7, 2010) will be about figuring the center of a circle. <\/p>\n<p class=\"MsoNormal\">He will also ask me about how we are doing with Twitter. What can I say about Twitter?<\/p>\n<p class=\"MsoNormal\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>We have been meeting some really passionate Windows PowerShell people on Twitter.<\/p>\n<p class=\"MsoNormal\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>I have been invited to speak to one Windows PowerShell users group via Twitter.<\/p>\n<p class=\"MsoNormal\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>I have found several moderators for The Official Scripting Guys Forum via Twitter.<\/p>\n<p class=\"MsoNormal\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>I have answered dozens of questions from various users via Twitter.<\/p>\n<p class=\"MsoNormal\"><span><span>&middot;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>I have received some really cool ideas for the 2010 Scripting Games via Twitter.<\/p>\n<p class=\"MsoNormal\">Cool, I am all set for my one-on-one. I still have some more time. Let me look through some of my pictures. I have been trying to collect all of my digital pictures into a single location in order to get a good backup of them. It is somewhat of a challenge when you own a dozen computers. I have 7 computers in my office right now. The rest of the computers are spread throughout the house. Unfortunately, through the years I have been very sloppy about\norganizing my digital pictures. One day I will write some scripts to help me with the pictures. Here is one cool picture I took during the time I was teaching a WMI class in Munich, Germany. One Saturday, I took the train to Salzburg, Austria. I took the following picture that day.<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of Salzburg, Austria\" alt=\"Image of Salzburg, Austria\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/january\/hey0126\/hsg-01-26-10-01.jpg\" width=\"600\" height=\"450\"><\/p>\n<p class=\"Fig-Graphic\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"MsoNormal\">DA, I am back from my one-on-one with the Scripting Manager. You will be glad to know that using the AD DS Windows PowerShell cmdlets can be extremely easy. For example, to create an organizational unit (OU) in Active Directory, all you need to do is to supply the name and the path. The behavior is exactly the same as creating a new user in Active Directory, which we discussed <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2010\/01\/25\/hey-scripting-guy-january-25-2010.aspx\">yesterday<\/a>. <\/p>\n<p class=\"MsoNormal\">To create a new OU, use the <b>New-ADOrganizationalUnit<\/b> cmdlet:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">New-ADOrganizationalUnit -Name HSG_TestOU -Path &#8220;dc=nwtraders,dc=com&#8221;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">If you wish to create a child OU, you use the <b>New-ADOrganizationalUnit<\/b> cmdlet, but in the path, you list the location that will serve as the parent:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">New-ADOrganizationalUnit -Name HSG_TestOU1 -Path &#8220;ou=HSG_TestOU,dc=nwtraders,dc=com&#8221;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">If you wish to make several child OUs in the same location, press the up arrow to retrieve the previous command and edit the name of the child. You can press the HOME key to move to the beginning of the line, the END key to move to the end of the line, and the left and right arrow keys to quickly find your place on the line so you can edit it. A second child OU is created here:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">New-ADOrganizationalUnit -Name HSG_TestOU2 -Path &#8220;ou=HSG_TestOU,dc=nwtraders,dc=com&#8221;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">The newly created OUs are seen in the following image.<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of newly created OUs\" alt=\"Image of newly created OUs\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/january\/hey0126\/hsg-01-26-10-02.jpg\" width=\"600\" height=\"408\"><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/january\/hey0126\/hsg-01-26-10-02.jpg\"><\/a><\/p>\n<p class=\"Fig-Graphic\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"MsoNormal\">To create a computer account in one of the newly created child OUs, you must type the complete path to the OU that will house the new computer account. The <b>New-ADComputer<\/b> cmdlet is used to create new computer accounts in AD DS. In this example, the <b>HSG_TestOU1<\/b> OU is a child of the <b>HSG_TestOU<\/b> OU; therefore, both OUs must appear in the <b>path<\/b> parameter. Keep in mind that the path that is supplied to the <b>path<\/b> parameter must be contained inside quotation marks, as seen here:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">New-ADComputer -Name HSG_Test -Path &#8220;ou=HSG_TestOU1,ou=HSG_TestOU,dc=nwtraders,dc=com&#8221;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">To create a user account, use the <b>New-ADUser<\/b> cmdlet, as seen here:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">New-ADUser -Name HSG_TestChild -Path &#8220;ou=HSG_TestOU1,ou=HSG_TestOU,dc=nwtraders,dc=com&#8221;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">Because there could be some redundant typing involved, you may wish to write a script to create the OUs at the same time the computer accounts and user accounts are created. A sample script that creates OUs, users, and computers is the UseADCmdletsToCreateOuComputerAndUser.ps1 script seen here. <\/p>\n<p class=\"CodeBlockScreenedHead\"><strong>UseADCmdletsToCreateOuComputerAndUser.ps1<\/p>\n<p><\/strong><\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">Import-Module -Name ActiveDirectory<br \/>$Name = &#8220;HSG_ScriptTest&#8221;<br \/>$DomainName = &#8220;dc=nwtraders,dc=com&#8221;<br \/>$OUPath = &#8220;ou={0},{1}&#8221; -f $Name, $DomainName<\/p>\n<p>New-ADOrganizationalUnit -Name $Name -Path $DomainName -ProtectedFromAccidentalDeletion $false<\/p>\n<p>For($i = 0; $i -le 5; $i++)<br \/>{<br \/><span>&nbsp;<\/span>New-ADOrganizationalUnit -Name $Name$i -Path $OUPath -ProtectedFromAccidentalDeletion $false<br \/>}<\/p>\n<p>For($i = 0 ; $i -le 5; $i++)<br \/>{<br \/><span>&nbsp;<\/span>New-ADComputer -Name<span>&nbsp; <\/span>&#8220;HSGTestComputer$i&#8221; -Path $OUPath<br \/><span>&nbsp;<\/span>New-ADUser -Name &#8220;HSGTestUser$i&#8221; -Path $OUPath<br \/>}<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">The UseADCmdletsToCreateOuComputerAndUser.ps1 script begins by importing the <b>ActiveDirectory<\/b> module. It then creates the first OU. When testing a script, it is important to disable the deletion protection by using the <b>&ndash;ProtectedFromAccidentalDeletion<\/b> parameter. This will allow you to easily delete the OU and avoid having to go into the advanced view in Active Directory Users and Computers and changing the protected status on each OU. <\/p>\n<p class=\"MsoNormal\">After the <b>HSG_ScriptTest<\/b> OU is created, the other OUs, users, and computer accounts can be created inside the new location. It seems obvious that you cannot create a child OU inside the parent OU if the parent has not yet been created, but it is easy to make a logic error like this. <\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p>\n<\/p>\n<p class=\"MsoNormal\">DA, that is all there is to using the Active Directory Domain Services Windows PowerShell cmdlets to create new OUs, computer accounts, and user accounts. Active Directory Week will continue tomorrow. <\/p>\n<p class=\"MsoNormal\">If you want to know exactly what we will be looking at tomorrow, follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\"><font face=\"Segoe\">Facebook<\/font><\/a>. If you have any questions, send e-mail to us at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a> or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p>\n<\/p>\n<p><b><span>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/p>\n<p><\/span><\/b><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Hey, Scripting Guy! I am interested in using Active Directory Domain Services (AD DS) cmdlets to create users and organizational units. Is this a hard thing to do? I only ask this because I am an extremely busy network administrator who has barely had time to begin looking at Windows PowerShell. I do not [&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,46,43,3,20,45],"class_list":["post-51483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-computer-accounts","tag-ous","tag-scripting-guy","tag-user-accounts","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp; Hey, Scripting Guy! I am interested in using Active Directory Domain Services (AD DS) cmdlets to create users and organizational units. Is this a hard thing to do? I only ask this because I am an extremely busy network administrator who has barely had time to begin looking at Windows PowerShell. I do not [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51483","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=51483"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51483\/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=51483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=51483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=51483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}