<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='http://dverweij.spaces.live.com/mmm2008-07-24_12.50/rsspretty.aspx?rssquery=en-US;http%3a%2f%2fdverweij.spaces.live.com%2fcategory%2fActive%2bDirectory%2ffeed.rss' version='1.0'?><rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:msn="http://schemas.microsoft.com/msn/spaces/2005/rss" xmlns:live="http://schemas.microsoft.com/live/spaces/2006/rss" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Just Powershell it: Active Directory</title><description /><link>http://dverweij.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&amp;_c=BlogPart&amp;partqs=catActive%2bDirectory</link><language>en-US</language><pubDate>Sat, 12 Jul 2008 01:36:10 GMT</pubDate><lastBuildDate>Sat, 12 Jul 2008 01:36:10 GMT</lastBuildDate><generator>Microsoft Spaces v1.1</generator><docs>http://www.rssboard.org/rss-specification</docs><ttl>60</ttl><cf:parentRSS>http://dverweij.spaces.live.com/blog/feed.rss</cf:parentRSS><live:type>blogcategory</live:type><live:identity><live:id>-6645245869990399496</live:id><live:alias>dverweij</live:alias></live:identity><cf:listinfo><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="typelabel" label="Type" /><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="tag" label="Tag" /><cf:group element="category" label="Category" /><cf:sort element="pubDate" label="Date" data-type="date" default="true" /><cf:sort element="title" label="Title" data-type="string" /><cf:sort ns="http://purl.org/rss/1.0/modules/slash/" element="comments" label="Comments" data-type="number" /></cf:listinfo><item><title>Changing the incorrect homedir path of all users</title><link>http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!129.entry</link><description>&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;This powershell script is to correct the users homedrive path in Active Directory. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;The following steps are done by the script:&lt;/div&gt;
&lt;div&gt;- First it looks up the users with an incorrect homedrive annotation&lt;/div&gt;
&lt;div&gt;- For those users it changes the, in this case, servername to an alias&lt;/div&gt;
&lt;div&gt;- save the info an continue with the next one.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;# Powershell script&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;# Citrix Export published applications&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;# D. Verweij&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;#&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;###&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;# Connect to the AD&lt;/font&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;$root = [adsi]'LDAP://OU=users,OU=application,OU=services,DC=face,DC=foo,DC=nl'&lt;br&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;# Configure the searcher&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;$searcher = new-object directoryservices.directorysearcher&lt;br&gt;$searcher.searchroot = $root&lt;br&gt;$searcher.filter = &amp;quot;(objectclass=user)&amp;quot;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;&lt;em&gt;&lt;font color="#c0c0c0"&gt;# Loop up accounts with an incorrect homedrive&lt;/font&gt;&lt;/em&gt;&lt;br&gt;$searcher.findall()|where {$_.properties.item(&amp;quot;homedirectory&amp;quot;) -like &amp;quot;*servername*&amp;quot;}|foreach {&lt;br&gt;   $userrt=&amp;quot;&lt;/font&gt;&lt;a&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;LDAP://&amp;quot;+$_.properties.item(&amp;quot;distinguishedName&lt;/font&gt;&lt;/a&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;&amp;quot;)&lt;br&gt;   $userads = [adsi]$userrt&lt;br&gt;   $userhome=$userads.homedirectory&lt;br&gt;   $userads.put(&amp;quot;homedirectory&amp;quot;,$userhome.psbase.value.replace(&amp;quot;servername&amp;quot;,&amp;quot;serveralias&amp;quot;))&lt;br&gt;   $userads.setinfo()&lt;br&gt;}&lt;/font&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Grt&lt;/div&gt;
&lt;div&gt;Dennis&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-6645245869990399496&amp;page=RSS%3a+Changing+the+incorrect+homedir+path+of+all+users&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=dverweij.spaces.live.com&amp;amp;GT1=dverweij"&gt;</description><comments>http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!129.entry#comment</comments><guid isPermaLink="true">http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!129.entry</guid><pubDate>Fri, 29 Dec 2006 08:02:17 GMT</pubDate><slash:comments>2</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://dverweij.spaces.live.com/blog/cns!A3C75816DA1731F8!129/comments/feed.rss</wfw:commentRss><wfw:comment>http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!129.entry#comment</wfw:comment><dcterms:modified>2006-12-29T08:02:26Z</dcterms:modified></item><item><title>Move computer objects in Active Directory</title><link>http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!115.entry</link><description>&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;For our test enviroment we use a seperate OU in Active Directory to test WSUS updates and patches. Servers are put in this OU when patches have to be tested on curtain servers. To automate this, I of course, created a powershell script to do just this. &lt;/div&gt;
&lt;div&gt;The following had to be realized:&lt;/div&gt;
&lt;div&gt;- Create a script that moves the server to the test OU&lt;/div&gt;
&lt;div&gt;- The script had to be launched as an Altiris job with the abbility to run it on several server at the same time&lt;/div&gt;
&lt;div&gt;- For every server the original OU must be remembered to, with the next job, move it back&lt;/div&gt;
&lt;div&gt;- Another job (script) has to put the computer in the original OU after the updates are finished&lt;/div&gt;
&lt;div&gt;- One problem..the Altiris server runs in a different domain and there's no trust between the two domains&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;So I had to move the server to the test OU and had to remember the original OU to move it back and this for an unlimited number of servers at the same time.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Since the job must run from Altiris, dragged to a server, servergroup or scheduled on several servers, the server name must be given as a parameter. &lt;/div&gt;
&lt;div&gt;The Altiris job does the following things:&lt;/div&gt;
&lt;div&gt;- copy the script to the specified server in the %systemroot%\Temp directory&lt;/div&gt;
&lt;div&gt;- start the script as in a scheduled task : &lt;/div&gt;
&lt;div&gt;         %systemroot%\system32\WindowsPowershell\v1.0\powershell.exe %systemroot%\Temp\scriptname %computername%&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;The following script is to move the server.&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;&lt;/em&gt;&lt;/font&gt; &lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;# Powershell script&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;# WSUS Moving computer object to the Test OU&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;# D. Verweij&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;#&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;###&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;# First read the given parameter in the variable $servnm&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;param([string]$servnm=&amp;quot;none&amp;quot;)&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;&lt;em&gt;&lt;font color="#c0c0c0"&gt;# Specify the name of the logfile to save the original OU in. This file is saved on the machine you move and run the script&lt;br&gt;&lt;/font&gt;&lt;/em&gt;$ServFL = &amp;quot;C:\Altiris\logfiles\$servnm&amp;quot;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;&lt;font color="#c0c0c0"&gt;&lt;em&gt;# Specify the target OU&lt;br&gt;&lt;/em&gt;&lt;/font&gt;$patchOU=&amp;quot;&lt;/font&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;LDAP://OU=WSUSTest,OU=Services,DC=Dennis,DC=Verweij,DC=nl&amp;quot;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;&lt;em&gt;&lt;font color="#c0c0c0"&gt;# Connect to the root of the domain&lt;br&gt;&lt;/font&gt;&lt;/em&gt;$ad1=[adsi]''&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;&lt;em&gt;&lt;font color="#c0c0c0"&gt;# Setup the search criteria&lt;br&gt;&lt;/font&gt;&lt;/em&gt;$ad1search = new-object directoryservices.directorysearcher&lt;br&gt;$ad1search.searchroot = $ad1&lt;br&gt;$ad1search.filter=&amp;quot;(objectclass=computer)&amp;quot;&lt;br&gt;$serv2=$ad1search.findall()|where {$_.properties.item(&amp;quot;cn&amp;quot;) -like $servnm}&lt;br&gt;&lt;em&gt;&lt;font color="#c0c0c0"&gt;# Save the distinguishedname of the original OU in the logfile. You need the distinguished name to move it back &lt;/font&gt;&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;$serv2.properties.item(&amp;quot;distinguishedname&amp;quot;) &amp;gt; $ServFL&lt;br&gt;$servDN=$serv2.properties.item(&amp;quot;distinguishedname&amp;quot;)&lt;br&gt;&lt;em&gt;&lt;font color="#c0c0c0"&gt;# Connect to the computerobject&lt;/font&gt;&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;$serv=[adsi]&amp;quot;&lt;/font&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;LDAP://$servDN&amp;quot;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;&lt;em&gt;&lt;font color="#c0c0c0"&gt;# And move it&lt;br&gt;&lt;/font&gt;&lt;/em&gt;$serv.psbase.MoveTo($patchOU)&lt;/font&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;To move it back the Altiris job is pretty much the same except for the script name&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;The script to put it back:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;# Powershell script&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;# WSUS Moving computer object to the original OU&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;# D. Verweij&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;#&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;###&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;# First read the given parameter in the variable $servnm&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399"&gt;param([string]$servnm=&amp;quot;none&amp;quot;)&lt;br&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#ffffff"&gt;&lt;font style="background-color:#333399"&gt;&lt;font color="#c0c0c0"&gt;&lt;em&gt;# Specify the Test OU&lt;br&gt;&lt;/em&gt;&lt;/font&gt;$patchOU=&amp;quot;&lt;/font&gt;&lt;/font&gt;&lt;font style="background-color:#333399" color="#ffffff"&gt;LDAP://OU=WSUSTest,OU=Services,DC=Dennis,DC=Verweij,DC=nl&amp;quot;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#ffffff"&gt;&lt;font style="background-color:#333399"&gt;&lt;em&gt;&lt;font color="#c0c0c0"&gt;# Specify the name of the logfile the original OU is saved in&lt;br&gt;&lt;/font&gt;&lt;/em&gt;$ServFL = &amp;quot;C:\Altiris\logfiles\$servnm&amp;quot;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" color="#c0c0c0"&gt;&lt;em&gt;# Check if the logfile exists&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399"&gt;if(test-path $ServFL)&lt;br&gt;{&lt;br&gt;  &lt;em&gt;&lt;font color="#c0c0c0"&gt;# Read the logfile and get rid of the computername&lt;/font&gt;&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399"&gt;  gc $ServFL|%{$servDN = $_.ToUpper().replace(&amp;quot;CN=$servnm,&amp;quot;,&amp;quot;&amp;quot;)}&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399"&gt;  &lt;em&gt;&lt;font color="#c0c0c0"&gt;# Connect to the computerobject&lt;/font&gt;&lt;/em&gt;&lt;br&gt;  $serv = [adsi]&amp;quot;&lt;/font&gt;&lt;font style="background-color:#333399"&gt;LDAP://CN=$servnm,$patchOU&amp;quot;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399"&gt;  &lt;em&gt;&lt;font color="#c0c0c0"&gt;# And move it back were it came from&lt;/font&gt;&lt;/em&gt;&lt;br&gt;  $serv.psbase.MoveTo(&amp;quot;&lt;/font&gt;&lt;font style="background-color:#333399"&gt;LDAP://$servDN&amp;quot;&lt;/font&gt;&lt;font style="background-color:#333399"&gt;)&lt;br&gt;}&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399"&gt;&lt;em&gt;&lt;font color="#c0c0c0"&gt;# Finally delete the logfile&lt;/font&gt;&lt;/em&gt;&lt;br&gt;del $ServFL&lt;/font&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Hope you can do something with it!&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Grt&lt;/div&gt;
&lt;div&gt;Dennis&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-6645245869990399496&amp;page=RSS%3a+Move+computer+objects+in+Active+Directory&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=dverweij.spaces.live.com&amp;amp;GT1=dverweij"&gt;</description><comments>http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!115.entry#comment</comments><guid isPermaLink="true">http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!115.entry</guid><pubDate>Thu, 28 Dec 2006 10:40:07 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://dverweij.spaces.live.com/blog/cns!A3C75816DA1731F8!115/comments/feed.rss</wfw:commentRss><wfw:comment>http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!115.entry#comment</wfw:comment><dcterms:modified>2006-12-28T13:38:28Z</dcterms:modified></item></channel></rss>