<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>The Admin Guy's Blog</title>
	<atom:link href="http://theadminguy.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://theadminguy.wordpress.com</link>
	<description>A blog for the impatient System Administrators</description>
	<lastBuildDate>Sun, 22 Jan 2012 23:45:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='theadminguy.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>The Admin Guy's Blog</title>
		<link>http://theadminguy.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://theadminguy.wordpress.com/osd.xml" title="The Admin Guy&#039;s Blog" />
	<atom:link rel='hub' href='http://theadminguy.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Copy certificates from one server to another</title>
		<link>http://theadminguy.wordpress.com/2012/01/22/copy-certificates-from-one-server-to-another/</link>
		<comments>http://theadminguy.wordpress.com/2012/01/22/copy-certificates-from-one-server-to-another/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 23:34:46 +0000</pubDate>
		<dc:creator>The Admin Guy</dc:creator>
				<category><![CDATA[Certificates]]></category>
		<category><![CDATA[Powershell Scripts]]></category>
		<category><![CDATA[Windows Server]]></category>

		<guid isPermaLink="false">https://theadminguy.wordpress.com/?p=141</guid>
		<description><![CDATA[So for some reason, which until now remains a mystery, certificates where missing in the Trusted root certificate authorities certificate store on one of our servers. Of course one of the missing ones, was the one needed for a main part of the servers purpose, so that had to be fixed. While the certificates mmc [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=141&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So for some reason, which until now remains a mystery, certificates where missing in the Trusted root certificate authorities certificate store on one of our servers. </p>
<p>Of course one of the missing ones, was the one needed for a main part of the servers purpose, so that had to be fixed.</p>
<p>While the certificates mmc does permit the export on the source server and the import onto the broken one, working in the GUI, is just….</p>
<p>So I cooked up a Powershell script to do the job for me:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:c7d5a12c-4bf3-4b04-95c6-e6d0725ec6b8" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: powershell; auto-links: false; html-script: false; pad-line-numbers: true;">
&lt;#
.SYNOPSIS
Compares a given certificate store between 2 Windows machines. Copies missing to target if specified

.DESCRIPTION
The script compares the specified certificate store of the source machine against the target machine. 
If the Write switch is specified, the missing certificates are copied from the source machine to the target machine

.PARAMETER SourceServer
Source Machine name

.PARAMETER TargetServer
Target Machine name

.PARAMETER CertStore
Certificate store to be checked
Possible values of the store: 
My - Personal Store
Root - Trusted root certificate authorities
CertificateAuthority - Intermediate certificate authorities
AuthRoot - Third-party certificate authorities

.PARAMETER write
If specified, certificates missing on the target server will be copied to the target server

.INPUTS
System.String

.OUTPUTS
Console output
Certificates 

.EXAMPLE
Check-MachineCerts.ps1 -SourceServer &quot;SomeServer&quot; -TargetServer &quot;SomeServer&quot; -certstore &quot;AuthStore&quot;
Outputs the certificates missing in the Third-party certificate authorities store on the target machine as compared to the source machine

.EXAMPLE
Check-MachineCerts.ps1 -SourceServer &quot;SomeServer&quot; -TargetServer &quot;SomeServer&quot; -certstore &quot;My&quot; -write
Outputs the certificates missing in the Personal Store on the target machine as compared to the source machine. 
Copies the missing certificates to the target machine

.NOTES
Check-MachineCerts.ps1
by theAdminGuy - theadminguy.wordpress.com
#&gt;
Param(
	[Parameter(Mandatory=$true)][String]$SourceServer,
	[Parameter(Mandatory=$true)][String]$TargetServer,
	[Parameter(Mandatory=$true)]
		[ValidateSet(&quot;My&quot;,&quot;Root&quot;,&quot;CertificateAuthority&quot;,&quot;AuthRoot&quot;)]
		[String]$CertStore,
	[Parameter(Mandatory=$false)][switch]$write
)
#
#Connect to the source Root store (readonly)
$sourceStore = New-Object System.Security.Cryptography.X509Certificates.X509Store(&quot;\\$SourceServer\$CertStore&quot;,&quot;LocalMachine&quot;)
$sourceStore.open(&quot;ReadOnly&quot;)
#connect to the target store (readwrite)
$targetStore = New-Object System.Security.Cryptography.X509Certificates.X509Store(&quot;\\$TargetServer\$CertStore&quot;,&quot;LocalMachine&quot;)
$targetStore.open(&quot;ReadWrite&quot;)

$sourceCerts = $sourceStore.certificates
$targetCerts = $targetStore.certificates

Function CheckPrecense(){
Param(
    $sourcecert
)
	[int]$intCertFound = &quot;0&quot;
    $script:rtrCheckPrecense = &quot;CertNotFound&quot;
    ForEach ($targetcert in $targetCerts){     
        $test = $sourcecert.Equals($targetcert)
        if ($test -eq $true){
            $intCertFound++
        }
    }
    If ($intCertFound -ne &quot;0&quot;){
            $script:rtrCheckPrecense = &quot;CertFound&quot;
    }
} #end function 

foreach ($sourcecert in $sourceCerts){
    CheckPrecense $sourcecert
    If ($rtrCheckPrecense -eq &quot;CertNotFound&quot;){
        Write-Host `n`n $sourceCert.Subject &quot; was not found on &quot; $TargetServer
        If ($write -eq $true){
        	Write-Host `n &quot;Copying Certificate from &quot; $SourceServer `n
        	$targetStore.Add($sourceCert)
        }
    }
}
</pre>
</pre>
</div>
<p>Don’t judge me by the fact that the .Synopsis part of the script takes up half the lines in the script, but not being a programmer by trade, I am trying to improve on my documentation skills (as well as making myself able to reuse the script once I have forgotten it’s original purpose)</p>
<p>The script can be easily modified to also remove certs from the target, which is not present on the source.</p>
<p>Do let me know all your input, thoughts etc. </p>
<p>&#160;</p>
<p>/theadminguy</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theadminguy.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theadminguy.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theadminguy.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theadminguy.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/theadminguy.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/theadminguy.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/theadminguy.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/theadminguy.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theadminguy.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theadminguy.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theadminguy.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theadminguy.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theadminguy.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theadminguy.wordpress.com/141/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=141&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://theadminguy.wordpress.com/2012/01/22/copy-certificates-from-one-server-to-another/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/39c68a6445727e463ebf83d4c5b3c1fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">The Admin Guy</media:title>
		</media:content>
	</item>
		<item>
		<title>Powershell One-Liners &#8211; Process Monitor</title>
		<link>http://theadminguy.wordpress.com/2012/01/01/powershell-one-liners-process-monitor/</link>
		<comments>http://theadminguy.wordpress.com/2012/01/01/powershell-one-liners-process-monitor/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 18:58:42 +0000</pubDate>
		<dc:creator>The Admin Guy</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Monitor]]></category>
		<category><![CDATA[One-Liner]]></category>
		<category><![CDATA[Scheduled Tasks]]></category>

		<guid isPermaLink="false">https://theadminguy.wordpress.com/?p=135</guid>
		<description><![CDATA[As a server admin, I often face a situation where I have to perform an action on the server, but some process is running, and I have to wait. Rather than sitting around checking the server every 5 minutes, I set a Powershell one-liner monitor with notification: I simply add the above line same as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=135&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As a server admin, I often face a situation where I have to perform an action on the server, but some process is running, and I have to wait. </p>
<p>Rather than sitting around checking the server every 5 minutes, I set a Powershell one-liner monitor with notification:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:644fd2f0-da9b-4ed5-883b-ebcc733fe9bc" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: powershell; pad-line-numbers: true; wrap-lines: true;">
powershell.exe -command &quot;&amp; {if (! (get-process -name TheService -erroraction SilentlyContinue)){Send-MailMessage -SmtpServer 'theSMTPServer.void.null' -from theserver@rack.room -To 'theadmin@void.null -Subject 'TheService is not running, check theServer'}}&quot;
</pre>
</pre>
</div>
<p>I simply add the above line same as in the <a href="https://theadminguy.wordpress.com/2011/07/28/powershell-one-liners-folder-cleaning/">Folder cleaner</a></p>
<p>/theadminguy</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theadminguy.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theadminguy.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theadminguy.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theadminguy.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/theadminguy.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/theadminguy.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/theadminguy.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/theadminguy.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theadminguy.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theadminguy.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theadminguy.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theadminguy.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theadminguy.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theadminguy.wordpress.com/135/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=135&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://theadminguy.wordpress.com/2012/01/01/powershell-one-liners-process-monitor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/39c68a6445727e463ebf83d4c5b3c1fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">The Admin Guy</media:title>
		</media:content>
	</item>
		<item>
		<title>Powershell One-liners &#8211; Folder cleaning</title>
		<link>http://theadminguy.wordpress.com/2011/07/28/powershell-one-liners-folder-cleaning/</link>
		<comments>http://theadminguy.wordpress.com/2011/07/28/powershell-one-liners-folder-cleaning/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 14:27:14 +0000</pubDate>
		<dc:creator>The Admin Guy</dc:creator>
				<category><![CDATA[one-liner]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Windows Server]]></category>

		<guid isPermaLink="false">https://theadminguy.wordpress.com/2011/07/28/powershell-one-liners-folder-cleaning/</guid>
		<description><![CDATA[Some application just log to much, and the log files tend to get huge. Or maybe you have a situation where you just don’t need the log’s from the last 2 years, but would like to retain a few days back, in case of error: Windows Scheduled task and Powershell to the rescue &#160; This [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=121&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Some application just log to much, and the log files tend to get huge. </p>
<p>Or maybe you have a situation where you just don’t need the log’s from the last 2 years, but would like to retain a few days back, in case of error:</p>
<p>Windows Scheduled task and Powershell to the rescue</p>
<p>&#160;</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:d9a2bce5-fb6d-4123-b88f-dbb51ae36564" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: powershell; auto-links: false; light: false; pad-line-numbers: true; wrap-lines: true;">
powershell.exe -command &quot;&amp; {get-childitem -Path e:\IIS_Logs -Recurse| %{if ($_.CreationTime -lt ([DateTime]::Now.AddDays(-5))){remove-item $_.FullName}}}&quot;

</pre>
</pre>
</div>
<p>This will delete files older than 5 days in the targeted folder (IIS_logs) and all subfolders</p>
<p>I have tried to wrap this in a schtasks command, so far been unsuccessful.</p>
<p>In the Windows Server 2008 R2 GUI:</p>
<ul>
<li>Task Scheduler </li>
<li>Create a basic task </li>
<li>Give it a name and a description </li>
<li>Choose the Task trigger and the properties for the selected trigger </li>
<li>Choose the action (start a program) </li>
<li>Add the path for powershell.exe in the program/script box and everything following to the Add arguments (optional) box </li>
<li><a href="http://theadminguy.files.wordpress.com/2011/07/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://theadminguy.files.wordpress.com/2011/07/image_thumb.png?w=502&#038;h=147" width="502" height="147" /></a> </li>
<li>Review and Finish. </li>
</ul>
<ul>/theadminguy</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theadminguy.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theadminguy.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theadminguy.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theadminguy.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/theadminguy.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/theadminguy.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/theadminguy.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/theadminguy.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theadminguy.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theadminguy.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theadminguy.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theadminguy.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theadminguy.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theadminguy.wordpress.com/121/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=121&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://theadminguy.wordpress.com/2011/07/28/powershell-one-liners-folder-cleaning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/39c68a6445727e463ebf83d4c5b3c1fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">The Admin Guy</media:title>
		</media:content>

		<media:content url="http://theadminguy.files.wordpress.com/2011/07/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Powershell One-liners &#8211; IP scanner</title>
		<link>http://theadminguy.wordpress.com/2011/06/20/powershell-one-liners-ip-scanner/</link>
		<comments>http://theadminguy.wordpress.com/2011/06/20/powershell-one-liners-ip-scanner/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 15:23:45 +0000</pubDate>
		<dc:creator>The Admin Guy</dc:creator>
				<category><![CDATA[one-liner]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Windows Server]]></category>

		<guid isPermaLink="false">https://theadminguy.wordpress.com/2011/06/20/powershell-one-liners-ip-scanner/</guid>
		<description><![CDATA[So why use powershell? I even heard someone say “this powershell is so over-rated, what does it offer, that cannot be done with cmd.exe and a another tool?” Well, to me, that is exactly it, what does powershell offer, which cannot be done with cmd.exe? What if you wanted just to check a defined range [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=117&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So why use powershell? I even heard someone say “this powershell is so over-rated, what does it offer, that cannot be done with cmd.exe and a another tool?”</p>
<p>Well, to me, that is exactly it, what does powershell offer, which cannot be done with cmd.exe?</p>
<p>What if you wanted just to check a defined range of IP’s in you managed subnet, to find which ones have live hosts on them?</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:a51e7c8f-983e-470d-aa88-b403e9fca579" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: plain; pad-line-numbers: true;">
[PS]# 1..100 | %{ping -n 1 -w 15 11.2.7.$_ | select-string &quot;reply from&quot;}

Reply from 11.2.7.83: bytes=32 time=5ms TTL=122
Reply from 11.2.7.84: bytes=32 time=7ms TTL=122
Reply from 11.2.7.85: bytes=32 time=6ms TTL=122
Reply from 11.2.7.86: bytes=32 time=6ms TTL=122
Reply from 11.2.7.87: bytes=32 time=6ms TTL=122
Reply from 11.2.7.89: bytes=32 time=6ms TTL=122
Reply from 11.2.7.91: bytes=32 time=6ms TTL=122
Reply from 11.2.7.95: bytes=32 time=6ms TTL=122
Reply from 11.2.7.99: bytes=32 time=6ms TTL=122
</pre></p>
</div>
<p>This one-liner ping’s the range from 1 to 100 and returns the machines which replied.</p>
<p>The point here is not, that only Powershell can do this on Windows, and I know that ping.exe is not a native powershell cmd-let and what if the host does not respond to ICMP…bla bla.. <img class="wlEmoticon wlEmoticon-smile" style="border-style:none;" src="http://theadminguy.files.wordpress.com/2011/06/wlemoticon-smile.png?w=600" alt="Smile" /></p>
<p>But this method is simple, fast and intuitive. No need for starting up a dedicated application, no fiddling with scripts, just get the job done, which in turn leaves more room for other stuff.</p>
<p>/theadminguy</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theadminguy.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theadminguy.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theadminguy.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theadminguy.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/theadminguy.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/theadminguy.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/theadminguy.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/theadminguy.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theadminguy.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theadminguy.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theadminguy.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theadminguy.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theadminguy.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theadminguy.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=117&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://theadminguy.wordpress.com/2011/06/20/powershell-one-liners-ip-scanner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/39c68a6445727e463ebf83d4c5b3c1fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">The Admin Guy</media:title>
		</media:content>

		<media:content url="http://theadminguy.files.wordpress.com/2011/06/wlemoticon-smile.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>
	</item>
		<item>
		<title>Remove privileged folder in Windows 7</title>
		<link>http://theadminguy.wordpress.com/2011/06/14/remove-privileged-folder-in-windows-7/</link>
		<comments>http://theadminguy.wordpress.com/2011/06/14/remove-privileged-folder-in-windows-7/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 06:06:15 +0000</pubDate>
		<dc:creator>The Admin Guy</dc:creator>
				<category><![CDATA[Powershell Scripts]]></category>

		<guid isPermaLink="false">https://theadminguy.wordpress.com/?p=89</guid>
		<description><![CDATA[Ever found yourself in the situation where you wanted to delete a folder in Windows 7, but you can’t because it has special rights in some way? An example of such a folder could be the %windir%\winsxs. In my case I had attached a virtual disk file (.vmdk) from one virtual machine to a new [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=89&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ever found yourself in the situation where you wanted to delete a folder in Windows 7, but you can’t because it has special rights in some way?</p>
<p>An example of such a folder could be the %windir%\winsxs.</p>
<p>In my case I had attached a virtual disk file (.vmdk) from one virtual machine to a new virtual machine.</p>
<p>So I wanted to clean this disk of the unneeded Windows folder, but as this folder as well as most of the subfolders are owned by TrustedInstaller, not by the local Administrators group. For the %windir%\winsxs folder, the administrators group as well as the local system user (NT Authority\System) has only read access to the files.</p>
<p>In order to delete the folder you have to do two things:</p>
<ol>
<li>Take ownership of the folder and files</li>
<li>Grant the required user at least write access to the folder and files so they can be deleted</li>
</ol>
<p>The above can be done using the %windir%\system32\takeown.exe and the %windir%\system32\Icacls.exe</p>
<p>If doing this on one machine, then you could just run the respective command lines:</p>
<ul>
<li>takeown.exe /F d:\windows /R /D Y</li>
<li>Icacls.exe d:\windows /grant *&lt;UserSID&gt;:(F) /T /C</li>
</ul>
<p>But if you ever have to repeat it, then it should have been scripted:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:cb53ba25-991e-4fb9-8ead-5f1a608577e9" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: powershell;">
############
#Set-RestrictedFolderRights.ps1
#Set-RestrictedFolderRights -folder
############
param([string]$Folder=&quot;&quot;)
if($Folder -eq &quot;&quot;){Write-Host &quot;Please specify folder...&quot;;Break}
############
#Functions
############

Function Get-UserSID(){
	$sCurrentUser = [system.environment]::UserName
	$sCurrentUserdomain = [system.environment]::Userdomain
	$objUser = New-Object System.Security.Principal.NTAccount($sCurrentUserdomain, $sCurrentUser)
	$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
	$strSID.Value
}#end function Get-UserSID

############
#Main Script
############
$sSysFolder = ([system.environment]::SystemDirectory)
$sArgsA = '/F '+$Folder+' /A /R /D Y'

#grant ownership of the folder and all subfolders to the administrators group..
Start-Process -wait -FilePath &quot;$sSysFolder\takeown.exe&quot; -ArgumentList $sArgsA

#grant the logged on user full control of the folder and it's entire content
$sArgsB = $folder+' /grant *'+(Get-UserSID)+':(F) /T /C'
Start-Process -wait -FilePath &quot;$sSysFolder\icacls.exe&quot; -ArgumentList $sArgsB
</pre></p>
</div>
<p>The script takes the target folder as a parameter and then sets the rights:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:1eef7cd5-68c9-4a97-a2da-d8441c818685" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: plain;">
PS &gt; Set-RestrictedFolderRights -folder d:\Windows
</pre></p>
</div>
<p>After that the folder can be deleted.</p>
<p>A word of caution, there is no error checking in the script, so if you target the %systemroot% (usually c:\windows), the rights will be altered. As the script only adds permissions, the impact is not that huge, if the folder is not deleted after. But the rights are set in this manner for a reason</p>
<p><a href="http://technet.microsoft.com/en-us/library/cc731677(WS.10).aspx">http://technet.microsoft.com/en-us/library/cc731677(WS.10).aspx</a></p>
<p>/theadminguy</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theadminguy.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theadminguy.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theadminguy.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theadminguy.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/theadminguy.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/theadminguy.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/theadminguy.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/theadminguy.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theadminguy.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theadminguy.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theadminguy.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theadminguy.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theadminguy.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theadminguy.wordpress.com/89/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=89&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://theadminguy.wordpress.com/2011/06/14/remove-privileged-folder-in-windows-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/39c68a6445727e463ebf83d4c5b3c1fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">The Admin Guy</media:title>
		</media:content>
	</item>
		<item>
		<title>Export DHCP scopes and their address pools to a csv file</title>
		<link>http://theadminguy.wordpress.com/2010/04/15/export-dhcp-scopes-and-their-address-pools-to-a-csv-file/</link>
		<comments>http://theadminguy.wordpress.com/2010/04/15/export-dhcp-scopes-and-their-address-pools-to-a-csv-file/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 11:06:07 +0000</pubDate>
		<dc:creator>The Admin Guy</dc:creator>
				<category><![CDATA[DHCP]]></category>
		<category><![CDATA[Powershell Scripts]]></category>
		<category><![CDATA[Windows Server]]></category>

		<guid isPermaLink="false">http://theadminguy.wordpress.com/2010/04/15/export-dhcp-scopes-and-their-address-pools-to-a-csv-file/</guid>
		<description><![CDATA[Because I love regular expressions, and I had a need for it, I have modified my previously posted DHCP export script: $a = (netsh dhcp server 1.1.1.1 show scope) $lines = @() #start by looking for lines where there is IP present foreach ($i in $a){ if ($i -match "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"){ $lines += $i.Trim() } } [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=81&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Because I love regular expressions, and I had a need for it, I have modified my previously posted DHCP export script:</p>
<p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:3db69e61-5a1a-48bc-be8b-8f8a11a16307" class="wlWriterEditableSmartContent">
<pre style="background-color:Silver;overflow:auto;"><span style="color:#800080;">$a</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> (netsh dhcp server </span><span style="color:#000000;">1.1</span><span style="color:#000000;">.</span><span style="color:#000000;">1.1</span><span style="color:#000000;"> show scope)

</span><span style="color:#800080;">$lines</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">@</span><span style="color:#000000;">()
</span><span style="color:#008000;">#</span><span style="color:#008000;">start by looking for lines where there is IP present</span><span style="color:#008000;">
</span><span style="color:#0000FF;">foreach</span><span style="color:#000000;"> (</span><span style="color:#800080;">$i</span><span style="color:#000000;"> </span><span style="color:#0000FF;">in</span><span style="color:#000000;"> </span><span style="color:#800080;">$a</span><span style="color:#000000;">){
    </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#800080;">$i</span><span style="color:#000000;"> </span><span style="color:#008080;">-match</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}</span><span style="color:#800000;">"</span><span style="color:#000000;">){
            </span><span style="color:#800080;">$lines</span><span style="color:#000000;"> </span><span style="color:#000000;">+=</span><span style="color:#000000;"> </span><span style="color:#800080;">$i</span><span style="color:#000000;">.Trim()
    }
}

</span><span style="color:#800080;">$csvfile</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">@</span><span style="color:#000000;">()
</span><span style="color:#800080;">$lines2</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">@</span><span style="color:#000000;">()
</span><span style="color:#0000FF;">foreach</span><span style="color:#000000;"> (</span><span style="color:#800080;">$l</span><span style="color:#000000;"> </span><span style="color:#0000FF;">in</span><span style="color:#000000;"> </span><span style="color:#800080;">$lines</span><span style="color:#000000;">){
    </span><span style="color:#800080;">$Row</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800000;">""</span><span style="color:#000000;"> </span><span style="color:#000000;">|</span><span style="color:#000000;"> select Subnet,SubNetMask,ScopeStart,ScopeEnd,Location
    </span><span style="color:#800080;">$l</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$l</span><span style="color:#000000;"> </span><span style="color:#000000;">+</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">`n</span><span style="color:#800000;">"</span><span style="color:#000000;">
    </span><span style="color:#800080;">$l</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$l</span><span style="color:#000000;"> </span><span style="color:#008080;">-replace</span><span style="color:#000000;"> '</span><span style="color:#000000;">-</span><span style="color:#000000;">Active',''
    </span><span style="color:#800080;">$l</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$l</span><span style="color:#000000;"> </span><span style="color:#008080;">-replace</span><span style="color:#000000;"> '</span><span style="color:#000000;">-</span><span style="color:#000000;">',','
    </span><span style="color:#800080;">$l</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$l</span><span style="color:#000000;"> </span><span style="color:#008080;">-replace</span><span style="color:#000000;"> '\s',''
    </span><span style="color:#800080;">$Row</span><span style="color:#000000;">.Subnet </span><span style="color:#000000;">=</span><span style="color:#000000;"> (</span><span style="color:#800080;">$l</span><span style="color:#000000;">.Split(</span><span style="color:#800000;">"</span><span style="color:#800000;">,</span><span style="color:#800000;">"</span><span style="color:#000000;">))[</span><span style="color:#000000;">0</span><span style="color:#000000;">]
    </span><span style="color:#800080;">$c</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$Row</span><span style="color:#000000;">.Subnet
    </span><span style="color:#800080;">$Row</span><span style="color:#000000;">.SubNetMask </span><span style="color:#000000;">=</span><span style="color:#000000;"> (</span><span style="color:#800080;">$l</span><span style="color:#000000;">.Split(</span><span style="color:#800000;">"</span><span style="color:#800000;">,</span><span style="color:#800000;">"</span><span style="color:#000000;">))[</span><span style="color:#000000;">1</span><span style="color:#000000;">]
    </span><span style="color:#800080;">$Row</span><span style="color:#000000;">.Location </span><span style="color:#000000;">=</span><span style="color:#000000;"> (</span><span style="color:#800080;">$l</span><span style="color:#000000;">.Split(</span><span style="color:#800000;">"</span><span style="color:#800000;">,</span><span style="color:#800000;">"</span><span style="color:#000000;">))[</span><span style="color:#000000;">2</span><span style="color:#000000;">]
    </span><span style="color:#800080;">$b</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> (netsh dhcp server </span><span style="color:#000000;">1.1</span><span style="color:#000000;">.</span><span style="color:#000000;">1.1</span><span style="color:#000000;"> scope </span><span style="color:#800080;">$c</span><span style="color:#000000;"> show iprange)
    </span><span style="color:#0000FF;">foreach</span><span style="color:#000000;"> (</span><span style="color:#800080;">$i2</span><span style="color:#000000;"> </span><span style="color:#0000FF;">in</span><span style="color:#000000;"> </span><span style="color:#800080;">$b</span><span style="color:#000000;">){
        </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#800080;">$i2</span><span style="color:#000000;"> </span><span style="color:#008080;">-match</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}</span><span style="color:#800000;">"</span><span style="color:#000000;"> </span><span style="color:#008080;">-and</span><span style="color:#000000;"> </span><span style="color:#800080;">$i2</span><span style="color:#000000;"> </span><span style="color:#008080;">-notmatch</span><span style="color:#000000;"> 'Changed the current scope context to' `
            </span><span style="color:#008080;">-and</span><span style="color:#000000;"> </span><span style="color:#800080;">$i2</span><span style="color:#000000;"> </span><span style="color:#008080;">-notmatch</span><span style="color:#000000;"> 'No of IP Ranges : </span><span style="color:#000000;">1</span><span style="color:#000000;"> </span><span style="color:#0000FF;">in</span><span style="color:#000000;"> the Scope'){
            </span><span style="color:#800080;">$lines2</span><span style="color:#000000;"> </span><span style="color:#000000;">+=</span><span style="color:#000000;"> </span><span style="color:#800080;">$i2</span><span style="color:#000000;">.Trim()
        }
    }
    </span><span style="color:#0000FF;">Foreach</span><span style="color:#000000;"> (</span><span style="color:#800080;">$l2</span><span style="color:#000000;"> </span><span style="color:#0000FF;">in</span><span style="color:#000000;"> </span><span style="color:#800080;">$lines2</span><span style="color:#000000;">){
        </span><span style="color:#800080;">$l2</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$l2</span><span style="color:#000000;"> </span><span style="color:#008080;">-replace</span><span style="color:#000000;"> '</span><span style="color:#000000;">-</span><span style="color:#000000;">',','
        </span><span style="color:#800080;">$l2</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$l2</span><span style="color:#000000;"> </span><span style="color:#008080;">-replace</span><span style="color:#000000;"> '\s',''
        </span><span style="color:#800080;">$Row</span><span style="color:#000000;">.ScopeStart </span><span style="color:#000000;">=</span><span style="color:#000000;"> (</span><span style="color:#800080;">$l2</span><span style="color:#000000;">.Split(</span><span style="color:#800000;">"</span><span style="color:#800000;">,</span><span style="color:#800000;">"</span><span style="color:#000000;">))[</span><span style="color:#000000;">0</span><span style="color:#000000;">]
        </span><span style="color:#800080;">$Row</span><span style="color:#000000;">.ScopeEnd </span><span style="color:#000000;">=</span><span style="color:#000000;"> (</span><span style="color:#800080;">$l2</span><span style="color:#000000;">.Split(</span><span style="color:#800000;">"</span><span style="color:#800000;">,</span><span style="color:#800000;">"</span><span style="color:#000000;">))[</span><span style="color:#000000;">1</span><span style="color:#000000;">]
    }
    </span><span style="color:#800080;">$csvfile</span><span style="color:#000000;"> </span><span style="color:#000000;">+=</span><span style="color:#000000;"> </span><span style="color:#800080;">$Row</span><span style="color:#000000;">
}
</span><span style="color:#800080;">$csvfile</span><span style="color:#000000;"> </span><span style="color:#000000;">|</span><span style="color:#000000;"> sort</span><span style="color:#000000;">-</span><span style="color:#000000;">object Subnet </span><span style="color:#000000;">|</span><span style="color:#000000;"> Export</span><span style="color:#000000;">-</span><span style="color:#000000;">Csv </span><span style="color:#800000;">"</span><span style="color:#800000;">C:\Users\Public\Documents\DHCPExport.csv</span><span style="color:#800000;">"</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>The script put all the server scopes into a variable and then processes it.</p>
<p>As the <strong>netsh</strong> output is filled with headers and other stuff, quite a number of trims and –replacements are done.</p>
<p>The whole thing is then put into a csv file.</p>
<p>As usual any hints and pointers are welcomed. </p>
<p>/theadminguy</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theadminguy.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theadminguy.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theadminguy.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theadminguy.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/theadminguy.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/theadminguy.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/theadminguy.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/theadminguy.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theadminguy.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theadminguy.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theadminguy.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theadminguy.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theadminguy.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theadminguy.wordpress.com/81/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=81&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://theadminguy.wordpress.com/2010/04/15/export-dhcp-scopes-and-their-address-pools-to-a-csv-file/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/39c68a6445727e463ebf83d4c5b3c1fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">The Admin Guy</media:title>
		</media:content>
	</item>
		<item>
		<title>ESX VM guest listed as (invalid)</title>
		<link>http://theadminguy.wordpress.com/2009/12/13/esx-vm-guest-listed-as-invalid/</link>
		<comments>http://theadminguy.wordpress.com/2009/12/13/esx-vm-guest-listed-as-invalid/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 18:43:38 +0000</pubDate>
		<dc:creator>The Admin Guy</dc:creator>
				<category><![CDATA[ESX]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[VM]]></category>
		<category><![CDATA[vmx]]></category>

		<guid isPermaLink="false">http://theadminguy.wordpress.com/2009/12/13/esx-vm-guest-listed-as-invalid/</guid>
		<description><![CDATA[So we had a massive maintenance on one of our ESX clusters. The maintenance entailed the complete shutdown of all VMs and hosts in the cluster. The entire task went relatively fine, with the exception of the usual stuff like: HA configuration failed to apply to most of the hosts when they were powered on. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=80&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So we had a massive maintenance on one of our ESX clusters. The maintenance entailed the complete shutdown of all VMs and hosts in the cluster. The entire task went relatively fine, with the exception of the usual stuff like:</p>
<ul>
<li>HA configuration failed to apply to most of the hosts when they were powered on. Fix for this issue is straight forward: Disable HA for the cluster and re-enable it.</li>
</ul>
<p>&nbsp;</p>
<p>The upside to disabling HA when having to power-on multiple VMs (350+) is that they power-on faster, as the VMs do not have to go through HA admission control and you will of course receive no HA related errors <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<ul>
<li>Job queuing in VI causing VMs to take some time to power-on</li>
</ul>
<p>It appears to me that VI just throws all jobs in a pool and try to get to them as fast as possible. I would like the option to tell it to process a set amount of jobs at a time. This can of course be achieved with the power of shell, but if anybody knows how it can be done in the GUI, let me know.</p>
<p>But what about the invalid VM?</p>
<p>Well, one of the machines came up with the name in italics and with an (invalid) appended to the name… Of course the GUI did not provide much help. When attempting to power on the machine, the only message I got was a <strong>“not allowed in the the current state”</strong></p>
<p>Directed by this post: <a href="http://itsupportjournal.com/2008/12/09/fix-invalid-guest-on-virtual-center/">http://itsupportjournal.com/2008/12/09/fix-invalid-guest-on-virtual-center/</a> I started checking my .vmx file for errors and found.. none. As it turns out, my issue was in the extended config file (.vmxf)</p>
<p>This is what was in there:</p>
<p><a href="http://theadminguy.files.wordpress.com/2009/12/image_thumb1.png"><img class="alignnone size-medium wp-image-79" title="image_thumb.png" src="http://theadminguy.files.wordpress.com/2009/12/image_thumb1.png?w=300&#038;h=23" alt="" width="300" height="23" /></a></p>
<p>I started scratching my head, as it was obvious that the invalid came from this file, but how to create a new one, when the .vmxf file contains a unique identifier type string amongst others:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:ff815475-6f62-49a8-9496-eaa05b69c5d5" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<pre>(?xml version="1.0"?)
(Foundry)
(VM)
(VMId type="string")52 fc dd 7e 09 fa ac 07-46 87 01 ad 28 e5 ca 98(/VMId)
(ClientMetaData)
(clientMetaDataAttributes/)
(HistoryEventList/)(/ClientMetaData)
(vmxPathName type="string")vmname.vmx(/vmxPathName)(/VM)(/Foundry)</pre>
</div>
<p>Well sometimes the easy solution is the right one (love when that happens <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<ol>
<li>Unregister the invalid VM in VI</li>
<li>Open the datastore browser and browse to the folder containing the VM</li>
<li>Rename the original .vmxf file.</li>
<li>Register the VM in VI from the datastore browser (right-click –&gt; Add to inventory –&gt; Step through the wizard)</li>
<li>A new and proper .vmxf file is generated</li>
<li>Power-On the VM</li>
</ol>
<p>Do let me know if there is any way of “hand creating” the extended config file. Not that it is very useful if it can be automatically generated, but it would be cool to be able to do it…</p>
<p>/theAdminGuy</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theadminguy.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theadminguy.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theadminguy.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theadminguy.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/theadminguy.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/theadminguy.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/theadminguy.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/theadminguy.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theadminguy.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theadminguy.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theadminguy.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theadminguy.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theadminguy.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theadminguy.wordpress.com/80/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=80&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://theadminguy.wordpress.com/2009/12/13/esx-vm-guest-listed-as-invalid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/39c68a6445727e463ebf83d4c5b3c1fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">The Admin Guy</media:title>
		</media:content>

		<media:content url="http://theadminguy.files.wordpress.com/2009/12/image_thumb1.png?w=300" medium="image">
			<media:title type="html">image_thumb.png</media:title>
		</media:content>
	</item>
		<item>
		<title>Modify Disk layout in Windows using powershell &#8211; updated version</title>
		<link>http://theadminguy.wordpress.com/2009/11/13/modify-disk-layout-in-windows-using-powershell-updated-version/</link>
		<comments>http://theadminguy.wordpress.com/2009/11/13/modify-disk-layout-in-windows-using-powershell-updated-version/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 23:25:13 +0000</pubDate>
		<dc:creator>The Admin Guy</dc:creator>
				<category><![CDATA[Powershell Scripts]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Windows Server Automation]]></category>
		<category><![CDATA[Automation]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://theadminguy.wordpress.com/2009/11/13/modify-disk-layout-in-windows-using-powershell-updated-version/</guid>
		<description><![CDATA[At work one of my colleagues is fond of the phrase: Assume – makes and ass of you and me Now this has, again, become very appropriate for me to use: In my first post of the disk layout script, found here, I wrote with assumption and confidence: “but should also work on Windows Server [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=72&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>At work one of my colleagues is fond of the phrase: Assume – makes and <strong>ass</strong> of yo<strong>u</strong> and <strong>me</strong></p>
<p>Now this has, again, become very appropriate for me to use:</p>
<p>In my first post of the disk layout script, <a href="http://theadminguy.wordpress.com/2009/11/09/modify-disk-layout-in-windows-using-powershell/">found here</a>, I wrote with assumption and confidence: “<em>but should also work on Windows Server 2003, if it does not then I have to redo the Altiris job”…</em></p>
<p>So I have redone the Altiris job powershell script:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:8d071915-ab00-4f5e-9b3a-922551b03f41" class="wlWriterEditableSmartContent">
<pre style="background-color:#C0C0C0;overflow:auto;"><span style="color:#008000;">#</span><span style="color:#008000;">first we find and initialize physical disks with no partitions</span><span style="color:#008000;">
</span><span style="color:#800080;">$drives</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> gwmi Win32_diskdrive
</span><span style="color:#800080;">$scriptdisk</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$Null</span><span style="color:#000000;">
</span><span style="color:#800080;">$script</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$Null</span><span style="color:#000000;">
</span><span style="color:#800080;">$OSversion</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> (((Get</span><span style="color:#000000;">-</span><span style="color:#000000;">WmiObject Win32_operatingsystem).version).ToString()).Split('.')[</span><span style="color:#000000;">0</span><span style="color:#000000;">]

</span><span style="color:#0000FF;">foreach</span><span style="color:#000000;"> (</span><span style="color:#800080;">$disk</span><span style="color:#000000;"> </span><span style="color:#0000FF;">in</span><span style="color:#000000;"> </span><span style="color:#800080;">$drives</span><span style="color:#000000;">){
</span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#800080;">$disk</span><span style="color:#000000;">.Partitions </span><span style="color:#008080;">-eq</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">0</span><span style="color:#800000;">"</span><span style="color:#000000;">){
    </span><span style="color:#800080;">$drivenumber</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$disk</span><span style="color:#000000;">.DeviceID </span><span style="color:#008080;">-replace</span><span style="color:#000000;"> '[\\\\\.\\physicaldrive]',''

    </span><span style="color:#0000FF;">If</span><span style="color:#000000;"> (</span><span style="color:#800080;">$OSversion</span><span style="color:#000000;"> </span><span style="color:#008080;">-eq</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">5</span><span style="color:#800000;">"</span><span style="color:#000000;">){
</span><span style="color:#800080;">$script</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">@</span><span style="color:#800000;">"</span><span style="color:#800000;">
select disk $drivenumber
online noerr
create partition primary noerr
</span><span style="color:#800000;">"</span><span style="color:#000000;">@</span><span style="color:#000000;">
    }
    </span><span style="color:#0000FF;">ElseIf</span><span style="color:#000000;"> (</span><span style="color:#800080;">$OSversion</span><span style="color:#000000;"> </span><span style="color:#008080;">-eq</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">6</span><span style="color:#800000;">"</span><span style="color:#000000;">){
</span><span style="color:#800080;">$script</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">@</span><span style="color:#800000;">"</span><span style="color:#800000;">
select disk $drivenumber
online disk noerr
attributes disk clear readonly noerr
create partition primary noerr
format quick
</span><span style="color:#800000;">"</span><span style="color:#000000;">@</span><span style="color:#000000;">
}
    }
    </span><span style="color:#800080;">$drivenumber</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$Null</span><span style="color:#000000;">
    </span><span style="color:#800080;">$scriptdisk</span><span style="color:#000000;"> </span><span style="color:#000000;">+=</span><span style="color:#000000;"> </span><span style="color:#800080;">$script</span><span style="color:#000000;"> </span><span style="color:#000000;">+</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">`n</span><span style="color:#800000;">"</span><span style="color:#000000;">
    }
</span><span style="color:#800080;">$scriptdisk</span><span style="color:#000000;"> </span><span style="color:#000000;">|</span><span style="color:#000000;"> diskpart

</span><span style="color:#008000;">#</span><span style="color:#008000;">then we will move the CDRom drive to x:</span><span style="color:#008000;">
</span><span style="color:#000000;">(gwmi Win32_cdromdrive).drive </span><span style="color:#000000;">|</span><span style="color:#000000;"> </span><span style="color:#000000;">%</span><span style="color:#000000;">{</span><span style="color:#800080;">$a</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> mountvol </span><span style="color:#800080;">$_</span><span style="color:#000000;"> </span><span style="color:#000000;">/</span><span style="color:#000000;">l;mountvol </span><span style="color:#800080;">$_</span><span style="color:#000000;"> </span><span style="color:#000000;">/</span><span style="color:#000000;">d;</span><span style="color:#800080;">$a</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$a</span><span style="color:#000000;">.Trim();mountvol x: </span><span style="color:#800080;">$a</span><span style="color:#000000;">}

</span><span style="color:#008000;">#</span><span style="color:#008000;">then we will assign letters and labels to physical drives</span><span style="color:#008000;">
#</span><span style="color:#008000;"> thanks to powershell.com for this bit</span><span style="color:#008000;">
#</span><span style="color:#008000;">(http://powershell.com/cs/blogs/tips/archive/2009/01/15/enumerating-drive-letters.aspx)</span><span style="color:#008000;">
</span><span style="color:#800080;">$volumes</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> gwmi Win32_volume </span><span style="color:#000000;">|</span><span style="color:#000000;"> where {</span><span style="color:#800080;">$_</span><span style="color:#000000;">.BootVolume </span><span style="color:#008080;">-ne</span><span style="color:#000000;"> </span><span style="color:#0000FF;">$True</span><span style="color:#000000;"> </span><span style="color:#008080;">-and</span><span style="color:#000000;"> </span><span style="color:#800080;">$_</span><span style="color:#000000;">.SystemVolume </span><span style="color:#008080;">-ne</span><span style="color:#000000;"> </span><span style="color:#0000FF;">$True</span><span style="color:#000000;">}
</span><span style="color:#800080;">$letters</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">68</span><span style="color:#000000;">..</span><span style="color:#000000;">89</span><span style="color:#000000;"> </span><span style="color:#000000;">|</span><span style="color:#000000;"> </span><span style="color:#0000FF;">ForEach</span><span style="color:#000000;">-</span><span style="color:#000000;">Object { ([char]</span><span style="color:#800080;">$_</span><span style="color:#000000;">)</span><span style="color:#000000;">+</span><span style="color:#800000;">"</span><span style="color:#800000;">:</span><span style="color:#800000;">"</span><span style="color:#000000;"> }
</span><span style="color:#800080;">$freeletters</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$letters</span><span style="color:#000000;"> </span><span style="color:#000000;">|</span><span style="color:#000000;"> Where</span><span style="color:#000000;">-</span><span style="color:#000000;">Object {
  (New</span><span style="color:#000000;">-</span><span style="color:#000000;">Object System.IO.DriveInfo(</span><span style="color:#800080;">$_</span><span style="color:#000000;">)).DriveType </span><span style="color:#008080;">-eq</span><span style="color:#000000;"> 'NoRootDirectory'
}
</span><span style="color:#0000FF;">foreach</span><span style="color:#000000;"> (</span><span style="color:#800080;">$volume</span><span style="color:#000000;"> </span><span style="color:#0000FF;">in</span><span style="color:#000000;"> </span><span style="color:#800080;">$volumes</span><span style="color:#000000;">){
    </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#800080;">$volume</span><span style="color:#000000;">.DriveLetter </span><span style="color:#008080;">-eq</span><span style="color:#000000;"> </span><span style="color:#800080;">$Null</span><span style="color:#000000;">){
        </span><span style="color:#0000FF;">If</span><span style="color:#000000;"> (</span><span style="color:#800080;">$OSVersion</span><span style="color:#000000;"> </span><span style="color:#008080;">-eq</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">5</span><span style="color:#800000;">"</span><span style="color:#000000;">){
          mountvol </span><span style="color:#800080;">$freeletters</span><span style="color:#000000;">[</span><span style="color:#000000;">0</span><span style="color:#000000;">] </span><span style="color:#800080;">$volume</span><span style="color:#000000;">.DeviceID
          format </span><span style="color:#800080;">$freeletters</span><span style="color:#000000;">[</span><span style="color:#000000;">0</span><span style="color:#000000;">] </span><span style="color:#000000;">/</span><span style="color:#000000;">FS:NTFS </span><span style="color:#000000;">/</span><span style="color:#000000;">q </span><span style="color:#000000;">/</span><span style="color:#000000;">y
        }
        </span><span style="color:#0000FF;">Else</span><span style="color:#000000;"> {
            mountvol </span><span style="color:#800080;">$freeletters</span><span style="color:#000000;">[</span><span style="color:#000000;">0</span><span style="color:#000000;">] </span><span style="color:#800080;">$volume</span><span style="color:#000000;">.DeviceID
        }
    }
</span><span style="color:#800080;">$freeletters</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$letters</span><span style="color:#000000;"> </span><span style="color:#000000;">|</span><span style="color:#000000;"> Where</span><span style="color:#000000;">-</span><span style="color:#000000;">Object {
    (New</span><span style="color:#000000;">-</span><span style="color:#000000;">Object System.IO.DriveInfo(</span><span style="color:#800080;">$_</span><span style="color:#000000;">)).DriveType </span><span style="color:#008080;">-eq</span><span style="color:#000000;"> 'NoRootDirectory'
}
} </span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>As it turns out, diskpart v5.2 does not support either the <strong>online disk</strong> command nor the <strong>format quick</strong> command, which is why I have had to add OS filtering (got to love the one-liner <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  and the format command.</p>
<p>I have also had to remove the $_.DriveType -eq &quot;3&quot;, as an unformated primary partition under Windows Server 2003 R2 does not have a drivetype defined. But in order to salvage some honor, I’ll call that optimization, as it is actually not required, because that part of the script only assigns drive letters to volumes without one, and both the floppy and CDRom have one already.</p>
<p>/theadminguy</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theadminguy.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theadminguy.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theadminguy.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theadminguy.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/theadminguy.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/theadminguy.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/theadminguy.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/theadminguy.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theadminguy.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theadminguy.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theadminguy.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theadminguy.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theadminguy.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theadminguy.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=72&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://theadminguy.wordpress.com/2009/11/13/modify-disk-layout-in-windows-using-powershell-updated-version/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/39c68a6445727e463ebf83d4c5b3c1fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">The Admin Guy</media:title>
		</media:content>
	</item>
		<item>
		<title>Export DHCP leases to html using powershell &#8211; update</title>
		<link>http://theadminguy.wordpress.com/2009/11/09/export-dhcp-leases-to-html-using-powershell-update/</link>
		<comments>http://theadminguy.wordpress.com/2009/11/09/export-dhcp-leases-to-html-using-powershell-update/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 01:23:51 +0000</pubDate>
		<dc:creator>The Admin Guy</dc:creator>
				<category><![CDATA[DHCP]]></category>
		<category><![CDATA[Powershell Scripts]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://theadminguy.wordpress.com/2009/11/09/export-dhcp-leases-to-html-using-powershell-update/</guid>
		<description><![CDATA[There was a minor quirk in the original script, as lease dates where being mixed with hostnames in the final output html. As it turns out it was all a matter of what date it was, when I created the script Line 21 in the original: $l = $l -replace '[-]{1}\d{2}[/]\d{2}[/]\d{4}','' matches dates in the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=71&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There was a minor quirk in the original script, as lease dates where being mixed with hostnames in the final output html. As it turns out it was all a matter of what date it was, when I created the script <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Line 21 in the original: </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:65a779db-8777-410d-a1f4-f091c74b6c06" class="wlWriterEditableSmartContent">
<pre style="background-color:#C0C0C0;overflow:auto;"><span style="color:#800080;">$l</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$l</span><span style="color:#000000;"> </span><span style="color:#008080;">-replace</span><span style="color:#000000;"> '[</span><span style="color:#000000;">-</span><span style="color:#000000;">]{</span><span style="color:#000000;">1</span><span style="color:#000000;">}\d{</span><span style="color:#000000;">2</span><span style="color:#000000;">}[</span><span style="color:#000000;">/</span><span style="color:#000000;">]\d{</span><span style="color:#000000;">2</span><span style="color:#000000;">}[</span><span style="color:#000000;">/</span><span style="color:#000000;">]\d{</span><span style="color:#000000;">4</span><span style="color:#000000;">}',''</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>matches dates in the following format: <strong>-xx/yy/zzzz</strong> but not <strong>-x/yy/zzzz</strong> or for that matter <strong>-xx/y/zzzz</strong>. </p>
<p>The correct –replace should have been:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:546f90ff-9cfd-4bde-bf27-23ff9eca0d16" class="wlWriterEditableSmartContent">
<pre style="background-color:#C0C0C0;overflow:auto;"><span style="color:#800080;">$l</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$l</span><span style="color:#000000;"> </span><span style="color:#008080;">-replace</span><span style="color:#000000;"> '[</span><span style="color:#000000;">-</span><span style="color:#000000;">]{</span><span style="color:#000000;">1</span><span style="color:#000000;">}\d{</span><span style="color:#000000;">1</span><span style="color:#000000;">,</span><span style="color:#000000;">2</span><span style="color:#000000;">}[</span><span style="color:#000000;">/</span><span style="color:#000000;">]\d{</span><span style="color:#000000;">1</span><span style="color:#000000;">,</span><span style="color:#000000;">2</span><span style="color:#000000;">}[</span><span style="color:#000000;">/</span><span style="color:#000000;">]\d{</span><span style="color:#000000;">4</span><span style="color:#000000;">}',''</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>Thanks you for the comments, which was the final spark to get me to fix it in my production environment <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theadminguy.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theadminguy.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theadminguy.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theadminguy.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/theadminguy.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/theadminguy.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/theadminguy.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/theadminguy.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theadminguy.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theadminguy.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theadminguy.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theadminguy.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theadminguy.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theadminguy.wordpress.com/71/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=71&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://theadminguy.wordpress.com/2009/11/09/export-dhcp-leases-to-html-using-powershell-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/39c68a6445727e463ebf83d4c5b3c1fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">The Admin Guy</media:title>
		</media:content>
	</item>
		<item>
		<title>Modify disk layout in Windows using powershell</title>
		<link>http://theadminguy.wordpress.com/2009/11/09/modify-disk-layout-in-windows-using-powershell/</link>
		<comments>http://theadminguy.wordpress.com/2009/11/09/modify-disk-layout-in-windows-using-powershell/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 00:20:54 +0000</pubDate>
		<dc:creator>The Admin Guy</dc:creator>
				<category><![CDATA[Powershell Scripts]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Windows Server 2008]]></category>
		<category><![CDATA[Windows Server Automation]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Windows Server 2008 R2]]></category>

		<guid isPermaLink="false">http://theadminguy.wordpress.com/2009/11/09/modify-disk-layout-in-windows-using-powershell/</guid>
		<description><![CDATA[So I have been configuring the company Altiris server (I love that tool) with some new jobs. One of the headaches of past times, for me anyway, has been the modification of the disk layout, e.g. cd-rom must have letter so, a random number of physical disks must be formatted etc. This is the powershell [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=70&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So I have been configuring the company Altiris server (I love that tool) with some new jobs.</p>
<p>One of the headaches of past times, for me anyway, has been the modification of the disk layout, e.g. cd-rom must have letter so, a random number of physical disks must be formatted etc.</p>
<p>This is the powershell solution that I ended up with:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:03369c22-20ca-4b73-884f-02bff33c4958" class="wlWriterEditableSmartContent">
<pre style="background-color:#C0C0C0;overflow:auto;font-family:Verdana;font-size:9px;"><span style="color:#008000;">#</span><span style="color:#008000;">first we find and initialize physical disks with no partitions </span><span style="color:#008000;">
</span><span style="color:#800080;">$drives</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> gwmi Win32_diskdrive
</span><span style="color:#800080;">$scriptdisk</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$Null</span><span style="color:#000000;">
</span><span style="color:#800080;">$script</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$Null</span><span style="color:#000000;">
</span><span style="color:#0000FF;">foreach</span><span style="color:#000000;"> (</span><span style="color:#800080;">$disk</span><span style="color:#000000;"> </span><span style="color:#0000FF;">in</span><span style="color:#000000;"> </span><span style="color:#800080;">$drives</span><span style="color:#000000;">){
    </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#800080;">$disk</span><span style="color:#000000;">.Partitions </span><span style="color:#008080;">-eq</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">0</span><span style="color:#800000;">"</span><span style="color:#000000;">){
        </span><span style="color:#800080;">$drivenumber</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$disk</span><span style="color:#000000;">.DeviceID </span><span style="color:#008080;">-replace</span><span style="color:#000000;"> '[\\\\\.\\physicaldrive]',''
</span><span style="color:#800080;">$script</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">@</span><span style="color:#800000;">"</span><span style="color:#800000;">
select disk $drivenumber
online disk noerr
attributes disk clear readonly noerr
create partition primary noerr
format quick
</span><span style="color:#800000;">"</span><span style="color:#000000;">@</span><span style="color:#000000;">
}
</span><span style="color:#800080;">$drivenumber</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$Null</span><span style="color:#000000;">
</span><span style="color:#800080;">$scriptdisk</span><span style="color:#000000;"> </span><span style="color:#000000;">+=</span><span style="color:#000000;"> </span><span style="color:#800080;">$script</span><span style="color:#000000;"> </span><span style="color:#000000;">+</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">`n</span><span style="color:#800000;">"</span><span style="color:#000000;">
}
</span><span style="color:#800080;">$scriptdisk</span><span style="color:#000000;"> </span><span style="color:#000000;">|</span><span style="color:#000000;"> diskpart

</span><span style="color:#008000;">#</span><span style="color:#008000;">then we will move the CDRom drive to x:</span><span style="color:#008000;">
</span><span style="color:#000000;">(gwmi Win32_cdromdrive).drive </span><span style="color:#000000;">|</span><span style="color:#000000;"> </span><span style="color:#000000;">%</span><span style="color:#000000;">{</span><span style="color:#800080;">$a</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> mountvol </span><span style="color:#800080;">$_</span><span style="color:#000000;"> </span><span style="color:#000000;">/</span><span style="color:#000000;">l;mountvol </span><span style="color:#800080;">$_</span><span style="color:#000000;"> </span><span style="color:#000000;">/</span><span style="color:#000000;">d;</span><span style="color:#800080;">$a</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$a</span><span style="color:#000000;">.Trim();mountvol x: </span><span style="color:#800080;">$a</span><span style="color:#000000;">}

</span><span style="color:#008000;">#</span><span style="color:#008000;">then we will assign letters and labels to physical drives</span><span style="color:#008000;">
#</span><span style="color:#008000;"> thanks to powershell.com for this bit</span><span style="color:#008000;">
#</span><span style="color:#008000;">(http://powershell.com/cs/blogs/tips/archive/2009/01/15/enumerating-drive-letters.aspx)</span><span style="color:#008000;">
</span><span style="color:#800080;">$volumes</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> gwmi Win32_volume </span><span style="color:#000000;">|</span><span style="color:#000000;"> where {</span><span style="color:#800080;">$_</span><span style="color:#000000;">.BootVolume </span><span style="color:#008080;">-ne</span><span style="color:#000000;"> </span><span style="color:#0000FF;">$True</span><span style="color:#000000;"> </span><span style="color:#008080;">-and</span><span style="color:#000000;"> </span><span style="color:#800080;">$_</span><span style="color:#000000;">.SystemVolume </span><span style="color:#008080;">-ne</span><span style="color:#000000;"> </span><span style="color:#0000FF;">$True</span><span style="color:#000000;"> </span><span style="color:#008080;">-and</span><span style="color:#000000;"> </span><span style="color:#800080;">$_</span><span style="color:#000000;">.DriveType </span><span style="color:#008080;">-eq</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">3</span><span style="color:#800000;">"</span><span style="color:#000000;">}
</span><span style="color:#800080;">$letters</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">68</span><span style="color:#000000;">..</span><span style="color:#000000;">89</span><span style="color:#000000;"> </span><span style="color:#000000;">|</span><span style="color:#000000;"> </span><span style="color:#0000FF;">ForEach</span><span style="color:#000000;">-</span><span style="color:#000000;">Object { ([char]</span><span style="color:#800080;">$_</span><span style="color:#000000;">)</span><span style="color:#000000;">+</span><span style="color:#800000;">"</span><span style="color:#800000;">:</span><span style="color:#800000;">"</span><span style="color:#000000;"> }
</span><span style="color:#800080;">$freeletters</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$letters</span><span style="color:#000000;"> </span><span style="color:#000000;">|</span><span style="color:#000000;"> Where</span><span style="color:#000000;">-</span><span style="color:#000000;">Object {
  (New</span><span style="color:#000000;">-</span><span style="color:#000000;">Object System.IO.DriveInfo(</span><span style="color:#800080;">$_</span><span style="color:#000000;">)).DriveType </span><span style="color:#008080;">-eq</span><span style="color:#000000;"> 'NoRootDirectory'
}
</span><span style="color:#0000FF;">foreach</span><span style="color:#000000;"> (</span><span style="color:#800080;">$volume</span><span style="color:#000000;"> </span><span style="color:#0000FF;">in</span><span style="color:#000000;"> </span><span style="color:#800080;">$volumes</span><span style="color:#000000;">){
    </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#800080;">$volume</span><span style="color:#000000;">.DriveLetter </span><span style="color:#008080;">-eq</span><span style="color:#000000;"> </span><span style="color:#800080;">$Null</span><span style="color:#000000;">){
        mountvol </span><span style="color:#800080;">$freeletters</span><span style="color:#000000;">[</span><span style="color:#000000;">0</span><span style="color:#000000;">] </span><span style="color:#800080;">$volume</span><span style="color:#000000;">.DeviceID
    }
</span><span style="color:#800080;">$freeletters</span><span style="color:#000000;"> </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800080;">$letters</span><span style="color:#000000;"> </span><span style="color:#000000;">|</span><span style="color:#000000;"> Where</span><span style="color:#000000;">-</span><span style="color:#000000;">Object {
    (New</span><span style="color:#000000;">-</span><span style="color:#000000;">Object System.IO.DriveInfo(</span><span style="color:#800080;">$_</span><span style="color:#000000;">)).DriveType </span><span style="color:#008080;">-eq</span><span style="color:#000000;"> 'NoRootDirectory'
}
} </span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<h6></h6>
</p>
<h6></h6>
<p>The script has been tested in PSHv2 installed on Windows Server 2008 and in native Windows 2008 R2 PSH, but should also work on Windows Server 2003, if it does not then I have to redo the Altiris job <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> <font color="#008000"> <font size="2"><em>- Update 14-11-2009: As it turns out the above will not work under Windows server 2003 – the updated version can be found </em></font></font><a href="http://theadminguy.wordpress.com/2009/11/13/modify-disk-layout-in-windows-using-powershell-updated-version/"><font color="#008000" size="2"><em>here</em></font></a></p>
<p>The script first gets all the physical disks which have no partitions. Then it creates a script for use with diskpart. Once all physical disks are formatted, driveletters are assigned. First we move the cd-rom drive to <strong>x: </strong>then we loop through all volumes which are not BootVolume (e.g. c:\) or SystemVolume (W2k8 R2 reserved system partition)</p>
<p>Throw some comments or input to improve. I am particularly interested in a way to do this using .NET, so I do not have to use diskpart.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theadminguy.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theadminguy.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theadminguy.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theadminguy.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/theadminguy.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/theadminguy.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/theadminguy.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/theadminguy.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theadminguy.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theadminguy.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theadminguy.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theadminguy.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theadminguy.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theadminguy.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theadminguy.wordpress.com&amp;blog=5979753&amp;post=70&amp;subd=theadminguy&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://theadminguy.wordpress.com/2009/11/09/modify-disk-layout-in-windows-using-powershell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/39c68a6445727e463ebf83d4c5b3c1fa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">The Admin Guy</media:title>
		</media:content>
	</item>
	</channel>
</rss>
