{"id":7,"date":"2011-01-23T07:08:28","date_gmt":"2011-01-23T15:08:28","guid":{"rendered":"http:\/\/www.jeaz.org\/?p=7"},"modified":"2011-02-18T01:24:24","modified_gmt":"2011-02-18T09:24:24","slug":"set-all-users-home-directories-with-powershell","status":"publish","type":"post","link":"https:\/\/www.jeaz.org\/?p=7","title":{"rendered":"Set all user&#8217;s home directories with PowerShell"},"content":{"rendered":"<blockquote>\n<pre>Get-ADUser -SearchBase \"OU=Users,DC=test,DC=ad\" | % { Set-ADUser $_ -HomeDrive \"H:\" -HomeDirectory ('\\\\fileserver\\home\\' + $_.SamAccountName) }<\/pre>\n<\/blockquote>\n<p>Let me explain how this works briefly:<\/p>\n<blockquote>\n<pre>Get-ADUser = Get users from AD<\/pre>\n<pre>-SearchBase \"ldap\" = Root of the tree in AD to get users from<\/pre>\n<pre>| = Pipe, provide input of query to...<\/pre>\n<pre>% = ForEach item piped from query<\/pre>\n<pre>Set-ADUser = Write changes to AD<\/pre>\n<pre>$_ = item piped from query<\/pre>\n<pre>-HomeDrive \"X:\" = Sets home drive letter, requires colon and quotes!!<\/pre>\n<pre>-HomeDirectory = Home drive path<\/pre>\n<pre>$_.SamAccountName = item piped from query's property \"SamAccountName\" aka username.<\/pre>\n<\/blockquote>\n<p>We chose to use the username for the folders in the home directory storage, you don't necessarily have to.<\/p>\n<p>Notice the (paranthesis) which tell Powershell to take my string\u00c2\u00a0<span style=\"font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;\">\\\\fileserver\\home\\<\/span> and variable <span style=\"font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;\">$_.SamAccountName<\/span> and mush them together, passing both as the final string to -HomeDirectory<\/p>\n<p>Thanks #powershell on Freenode and MS documentation examples<\/p>\n<p>Technet on Set-ADUser:<\/p>\n<p><a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/ee617215.aspx\">http:\/\/technet.microsoft.com\/en-us\/library\/ee617215.aspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Get-ADUser -SearchBase &#8220;OU=Users,DC=test,DC=ad&#8221; | % { Set-ADUser $_ -HomeDrive &#8220;H:&#8221; -HomeDirectory (&#8216;\\\\fileserver\\home\\&#8217; + $_.SamAccountName) } Let me explain how this works briefly: Get-ADUser = Get users from AD -SearchBase &#8220;ldap&#8221; = Root of the tree in AD to get users from | = Pipe, provide input of query to&#8230; % = ForEach item piped from [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[8],"class_list":["post-7","post","type-post","status-publish","format-standard","hentry","category-scripting-tips","tag-powershell"],"_links":{"self":[{"href":"https:\/\/www.jeaz.org\/index.php?rest_route=\/wp\/v2\/posts\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jeaz.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jeaz.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jeaz.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jeaz.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7"}],"version-history":[{"count":0,"href":"https:\/\/www.jeaz.org\/index.php?rest_route=\/wp\/v2\/posts\/7\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jeaz.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jeaz.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jeaz.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}