{"id":220,"date":"2012-01-30T18:53:28","date_gmt":"2012-01-31T01:53:28","guid":{"rendered":"http:\/\/constantinekrick.com\/?p=220"},"modified":"2012-01-30T18:53:28","modified_gmt":"2012-01-31T01:53:28","slug":"powershell-set-aduser-and-changing-the-login-script","status":"publish","type":"post","link":"http:\/\/constantinekrick.com\/?p=220","title":{"rendered":"PowerShell : Set-ADUser and changing the login script"},"content":{"rendered":"<p>The Set-ADUser\u00a0is a very powerful cmdlet\u00a0that allows for changing a users attributes in Active Directory. In this article, the Set-ADUser will be used to demonstrate how to change the logon script portion of a Users account in Active Directory.<\/p>\n<p style=\"text-align: center;\">First, lets look at our User Account in question.<a href=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2012\/01\/ProfileDemo01.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-221 aligncenter\" title=\"ProfileDemo01\" src=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2012\/01\/ProfileDemo01-240x300.jpg\" alt=\"\" width=\"240\" height=\"300\" srcset=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2012\/01\/ProfileDemo01-240x300.jpg 240w, http:\/\/constantinekrick.com\/wp-content\/uploads\/2012\/01\/ProfileDemo01.jpg 478w\" sizes=\"(max-width: 240px) 100vw, 240px\" \/><\/a><\/p>\n<p style=\"text-align: left;\">The\u00a0logon script\u00a0is blank. There are 3 user accounts for this demo that we are going to change: ProfileDemo001, ProfileDemo002, ProfileDemo003.<\/p>\n<p style=\"text-align: left;\">In order to run the Set-ADUser command, we need to prepare some prep work.\u00a0First, a CSV file needs to be created with the usernames that are going to be changed.\u00a0 Below is a screenshot showing the CSV file inside Excel.<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-222 aligncenter\" title=\"ProfileDemo02\" src=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2012\/01\/ProfileDemo02.jpg\" alt=\"\" width=\"244\" height=\"176\" \/><\/p>\n<p style=\"text-align: left;\"><!--more-->It is now time to fire up PowerShell with Active Directory Modules.<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter\" title=\"ProfileDemo03\" src=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2012\/01\/ProfileDemo03-300x60.jpg\" alt=\"\" width=\"300\" height=\"60\" \/><\/p>\n<p style=\"text-align: left;\">The command is the following :<strong>\u00a0 Import-CSV ProfileDemo.csv | ForEach-Object {Set-ADUser\u00a0$_.Name -ScriptPath &#8220;\\\\logonScripts\\Demo.vbs&#8221;}<\/strong><\/p>\n<p style=\"text-align: left;\"><strong><span style=\"color: #000000;\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter  wp-image-224\" title=\"ProfileDemo04\" src=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2012\/01\/ProfileDemo04.jpg\" alt=\"\" width=\"677\" height=\"306\" srcset=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2012\/01\/ProfileDemo04.jpg 677w, http:\/\/constantinekrick.com\/wp-content\/uploads\/2012\/01\/ProfileDemo04-300x135.jpg 300w\" sizes=\"(max-width: 677px) 100vw, 677px\" \/><\/span><\/strong><\/p>\n<p style=\"text-align: left;\"><strong>Explanation of the Script : <\/strong>The Import-CSV section allows us to take a list of usernames, and feed (aka PIPE) them into the cmdlet\u00a0&#8220;ForEach-Object&#8221;. The ForEach-Object\u00a0is required since the Set-ADUser\u00a0does not accept piped input. The ForEach-Object\u00a0will go through all the names in the excel sheet, and set the parameters\u00a0as needed. A full list of the parameter options can be found at : <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/ee617215.aspx\">http:\/\/technet.microsoft.com\/en-us\/library\/ee617215.aspx<\/a>\u00a0 Once the script is done, we are left with the C:\\PS&gt; prompt.<\/p>\n<p style=\"text-align: left;\">To double-check, a quick glance at some of the users will show that the command has completed\u00a0successfully.<\/p>\n<p style=\"text-align: left;\"><a href=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2012\/01\/ProfileDemo05.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-226\" title=\"ProfileDemo05\" src=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2012\/01\/ProfileDemo05.jpg\" alt=\"\" width=\"417\" height=\"479\" srcset=\"http:\/\/constantinekrick.com\/wp-content\/uploads\/2012\/01\/ProfileDemo05.jpg 417w, http:\/\/constantinekrick.com\/wp-content\/uploads\/2012\/01\/ProfileDemo05-261x300.jpg 261w\" sizes=\"(max-width: 417px) 100vw, 417px\" \/><\/a><\/p>\n<p style=\"text-align: left;\"><strong>Summary :<\/strong>\u00a0The Set-ADUser\u00a0cmdlet\u00a0is a major time saver when combined with the Import-CSV and ForEach-object\u00a0cmdlets. Over time, I have noticed\u00a0that\u00a0I consistently use the following statement very often\u00a0&#8220;Import-CSV list.csv | ForEach-object {\u00a0X\u00a0}&#8221; where X is the cmdlet that does not accept a pipe input. Please leave questions in the comments if there are any problems.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Set-ADUser\u00a0is a very powerful cmdlet\u00a0that allows for changing a users attributes in Active Directory. In this article, the Set-ADUser will be used to demonstrate how to change the logon script portion of a Users account in Active Directory. First, &hellip; <a href=\"http:\/\/constantinekrick.com\/?p=220\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1x8ho-3y","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/constantinekrick.com\/index.php?rest_route=\/wp\/v2\/posts\/220"}],"collection":[{"href":"http:\/\/constantinekrick.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/constantinekrick.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/constantinekrick.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/constantinekrick.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=220"}],"version-history":[{"count":7,"href":"http:\/\/constantinekrick.com\/index.php?rest_route=\/wp\/v2\/posts\/220\/revisions"}],"predecessor-version":[{"id":232,"href":"http:\/\/constantinekrick.com\/index.php?rest_route=\/wp\/v2\/posts\/220\/revisions\/232"}],"wp:attachment":[{"href":"http:\/\/constantinekrick.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/constantinekrick.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/constantinekrick.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}