<?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/"
	>

<channel>
	<title>Andrew Morgan &#187; Server</title>
	<atom:link href="http://andrewmorgan.ie/tag/server/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewmorgan.ie</link>
	<description>Grumpy ramblings</description>
	<lastBuildDate>Fri, 30 Jun 2017 09:24:25 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0</generator>
	<item>
		<title>Viewing open files on a file server from powershell.</title>
		<link>http://andrewmorgan.ie/2012/12/viewing-open-files-on-a-file-server-from-powershell/</link>
		<comments>http://andrewmorgan.ie/2012/12/viewing-open-files-on-a-file-server-from-powershell/#comments</comments>
		<pubDate>Wed, 05 Dec 2012 14:55:23 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[Clustering]]></category>
		<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[Server Based Computing]]></category>
		<category><![CDATA[Virtual Desktop Infrastructure]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[XenApp]]></category>
		<category><![CDATA[XenDesktop]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SBC]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[VDI]]></category>
		<category><![CDATA[xenapp]]></category>

		<guid isPermaLink="false">http://andrewmorgan.ie/?p=2480</guid>
		<description><![CDATA[So this is a situation you should all be aware of in an SBC / VDI environment, despite all warnings, you&#8217;ve redirected folders to your network drive and your file servers are screaming in agony? Having been in this situation recently, I needed to audit and report on the types of files open on the file server, my hunch was a certain select number of users were running applications (like *gulp* lotus notes) from the network share. Disappointed with the [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img class="alignright size-full" alt="/wp-content/uploads/2011/03/windows_powershell_icon.png?w=58&amp;h=58&amp;h=58" src="/wp-content/uploads/2011/03/windows_powershell_icon.png?w=58&amp;h=58&amp;h=58" height="58" width="58" />So this is a situation you should all be aware of in an SBC / VDI environment, despite all <a href="http://helgeklein.com/blog/2011/11/folder-redirection-denial-of-service-waiting-to-happen/" target="_blank">warnings</a>, you&#8217;ve redirected folders to your network drive and your file servers are screaming in agony?</p>
<p>Having been in this situation recently, I needed to audit and report on the types of files open on the file server, my hunch was a certain select number of users were running applications (like *gulp* lotus notes) from the network share.</p>
<p>Disappointed with the powershell scripts on the interwebs, I decided to write my own function to perform this task:</p>
<p>[sourcecode language=&#8221;powershell&#8221;]<br />
function get-openfiles{<br />
param(<br />
    $computername=@($env:computername),<br />
    $verbose=$false)<br />
    $collection = @()<br />
foreach ($computer in $computername){<br />
    $netfile = [ADSI]&quot;WinNT://$computer/LanmanServer&quot;</p>
<p>        $netfile.Invoke(&quot;Resources&quot;) | foreach {<br />
            try{<br />
                $collection += New-Object PsObject -Property @{<br />
        		  Id = $_.GetType().InvokeMember(&quot;Name&quot;, &#8216;GetProperty&#8217;, $null, $_, $null)<br />
        		  itemPath = $_.GetType().InvokeMember(&quot;Path&quot;, &#8216;GetProperty&#8217;, $null, $_, $null)<br />
        		  UserName = $_.GetType().InvokeMember(&quot;User&quot;, &#8216;GetProperty&#8217;, $null, $_, $null)<br />
        		  LockCount = $_.GetType().InvokeMember(&quot;LockCount&quot;, &#8216;GetProperty&#8217;, $null, $_, $null)<br />
        		  Server = $computer<br />
        		}<br />
            }<br />
            catch{<br />
                if ($verbose){write-warning $error[0]}<br />
            }<br />
        }<br />
    }<br />
    Return $collection<br />
}<br />
[/sourcecode]</p>
<p>The function above (get-openfiles) has been written to accept an array of servers to the command line and it will return the following items:</p>
<ul>
<li>The ID of the open file.</li>
</ul>
<ul>
<li>The server it&#8217;s open from.</li>
</ul>
<ul>
<li>The username who has the file open.</li>
</ul>
<ul>
<li>The amount of locks the file has.</li>
</ul>
<p><strong>A couple of quick examples for using this command are below:<br />
<code><br />
</code><br />
</strong> <span style="text-decoration:underline;">Retrieving open files from server1:</span><br />
<code><br />
</code><br />
<img class="aligncenter" alt="full" src="/wp-content/uploads/2012/12/full.png" height="261" width="595" /><br />
<code><br />
</code></p>
<p>[sourcecode language=&#8221;powershell&#8221;]get-openfiles -computername server1 | select server,itempath,lockcount[/sourcecode]</p>
<p><code><br />
</code><br />
<span style="text-decoration:underline;">Retrieve a count of open files that end with the nsf file type (<em>Lotus Notes</em>):</span><br />
<code><br />
</code><br />
<img class="aligncenter size-full wp-image-2483" alt="count" src="/wp-content/uploads/2012/12/count.png" height="37" width="595" /><br />
<code><br />
</code></p>
<p>[sourcecode language=&#8221;powershell&#8221;](get-open files -computername server1,server2 | ? {$_.itempath -like &quot;*.nsf*&quot;}).count()[/sourcecode]</p>
<p><code><br />
</code><br />
<span style="text-decoration:underline;">Retrieve a report of total open files on a number of file servers:</span><br />
<code><br />
</code><br />
<img class="aligncenter size-full wp-image-2487" alt="report" src="/wp-content/uploads/2012/12/report.png" height="64" width="595" /></p>
<p>&nbsp;</p>
<p>[sourcecode language=&#8221;powershell&#8221;]get-openfiles -computername server1,server2,server3,server4,server5 | group -property server[/sourcecode]</p>
<p><code> </code></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2012/12/viewing-open-files-on-a-file-server-from-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Monitoring Storage disk queue&#8217;s and IO with PowerShell</title>
		<link>http://andrewmorgan.ie/2012/11/monitoring-storage-disk-queues-and-io-with-powershell/</link>
		<comments>http://andrewmorgan.ie/2012/11/monitoring-storage-disk-queues-and-io-with-powershell/#comments</comments>
		<pubDate>Fri, 30 Nov 2012 09:38:45 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[Citrix]]></category>
		<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[XenApp]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[xenapp]]></category>

		<guid isPermaLink="false">http://andrewmorgan.ie/?p=2469</guid>
		<description><![CDATA[Here&#8217;s one that used to bother me alot. The problem usually went as follows: &#8220;Your XenApp servers have very high disk queue&#8217;s and IO&#8221; &#8220;What&#8217;s causing it?&#8221; &#8220;dunno&#8230;&#8221; With Server 2008, the task manager&#8217;s resource monitor feature will help you find these items. But in server 2003 this was a perilous task. The specific details for disk io per process are stored in performance monitor under each specific process running. Trying to analyse each process was a massive pain, but [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img class="alignright size-full" alt="/wp-content/uploads/2011/03/windows_powershell_icon.png?w=58&amp;h=58&amp;h=58" src="/wp-content/uploads/2011/03/windows_powershell_icon.png?w=58&amp;h=58&amp;h=58" height="58" width="58" />Here&#8217;s one that used to bother me alot. The problem usually went as follows:</p>
<p>&#8220;Your XenApp servers have very high disk queue&#8217;s and IO&#8221;</p>
<p>&#8220;What&#8217;s causing it?&#8221;</p>
<p>&#8220;dunno&#8230;&#8221;</p>
<p>With Server 2008, the task manager&#8217;s resource monitor feature will help you find these items. But in server 2003 this was a perilous task. The specific details for disk io per process are stored in performance monitor under each specific process running. Trying to analyse each process was a massive pain, but powershell can do some very clever work to help alleviate this!</p>
<p>I wrote two quick functions which act similar to &#8220;top&#8221; in linux for giving an on screen view, updating at interval of what exactly is creating IO activity. These two functions are:</p>
<p>get-IODataBytes:</p>
<p><img class="aligncenter size-full wp-image-2470" alt="storageio" src="/wp-content/uploads/2012/11/storageio.png" height="233" width="595" /></p>
<p>Get-IODataOperations</p>
<p><img class="aligncenter size-full wp-image-2471" alt="storageioops" src="/wp-content/uploads/2012/11/storageioops.png" height="240" width="595" /></p>
<p>The code for these functions are below:</p>
<p>[sourcecode language=&#8221;powershell&#8221;]<br />
function get-iodatabytes{<br />
    $result=(get-counter -counter &quot;Process(*)IO Data Bytes/sec&quot; -ea 0).countersamples | ? {$_.cookedvalue -gt 0} | select instancename,@{Name=&quot;SessionID&quot;;Expression={if ($_.path.contains(&quot;#&quot;)){($_.path.split(&quot;#)&quot;))[1]}else{&quot;0&quot;}}},@{Name=&quot;IO Data Bytes/sec&quot;;Expression={[math]::Round($_.cookedvalue,0)}},@{Name=&quot;IO Data KBytes/sec&quot;;Expression={[math]::Round($_.cookedvalue / 1024,0)}} | sort -Descending &quot;IO Data Bytes/sec&quot; | ft<br />
    $currentqueue=(((get-counter -counter &quot;PhysicalDisk(0 C:)Current Disk Queue Length&quot; -ea 0).countersamples) | select cookedvalue).cookedvalue<br />
    clear<br />
    write-warning &quot;Hit [CTRL] + [C] to exit live capture&quot;<br />
    write-host &quot;Current Disk queue: $currentqueue&quot;<br />
    return $Result<br />
}</p>
<p>FUnction get-IODataOperations {<br />
    $result=(get-counter -counter &quot;Process(*)IO Data Operations/sec&quot; -ea 0).countersamples | ? {$_.cookedvalue -gt 0} | select instancename,@{Name=&quot;SessionID&quot;;Expression={if ($_.path.contains(&quot;#&quot;)){($_.path.split(&quot;#)&quot;))[1]}else{&quot;0&quot;}}},@{Name=&quot;IO Data Operations/sec&quot;;Expression={[math]::Round($_.cookedvalue,0)}} | sort -Descending &quot;IO Data Operations/sec&quot; | ft<br />
    $currentqueue=(((get-counter -counter &quot;PhysicalDisk(0 C:)Current Disk Queue Length&quot; -ea 0).countersamples) | select cookedvalue).cookedvalue<br />
    clear<br />
    write-warning &quot;Hit [CTRL] + [C] to exit live capture&quot;<br />
    write-host &quot;Current Disk queue: $currentqueue&quot;<br />
    return $Result<br />
}</p>
<p>[/sourcecode]</p>
<p>if you wish to loop one of these functions, simply use the following code:</p>
<p>[sourcecode language=&#8221;powershell&#8221;]<br />
while ($true){<br />
get-iodataoperations<br />
start-sleep 1<br />
}<br />
[/sourcecode]</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2012/11/monitoring-storage-disk-queues-and-io-with-powershell/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The curious case of missing file shares on a Microsoft File Server Cluster.</title>
		<link>http://andrewmorgan.ie/2012/01/the-curious-case-of-missing-file-shares-on-a-microsoft-file-server-cluster/</link>
		<comments>http://andrewmorgan.ie/2012/01/the-curious-case-of-missing-file-shares-on-a-microsoft-file-server-cluster/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 12:56:28 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[Clustering]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Cluster]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://andrewmorgan.ie/?p=1271</guid>
		<description><![CDATA[I had a very unusual issue recently where, after a fail over one of my file cluster resources didn&#8217;t publish all shares to the users. Some shares did come up, but many of the shares were missing resulting in users being locked out of their network drives. I immediately jumped to the registry HKEY_LOCAL_MACHINEClusterResources and found the resource by guid of my misbehaving file cluster. I could see all the shares missing were still published as resources as below: Upon reviewing the event logs, each [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="/wp-content/uploads/2012/01/cluster-icon.png"><img class="alignright size-full wp-image-1273" title="cluster icon" src="/wp-content/uploads/2012/01/cluster-icon.png" alt="" width="129" height="109" /></a>I had a very unusual issue recently where, after a fail over one of my file cluster resources didn&#8217;t publish all shares to the users. Some shares did come up, but many of the shares were missing resulting in users being locked out of their network drives.</p>
<p>I immediately jumped to the registry HKEY_LOCAL_MACHINEClusterResources and found the resource by guid of my misbehaving file cluster. I could see all the shares missing were still published as resources as below:</p>
<p><a href="/wp-content/uploads/2012/01/registry-entry.png"><img class="aligncenter size-full wp-image-1272" title="registry entry" src="/wp-content/uploads/2012/01/registry-entry.png" alt="" width="600" height="153" /></a></p>
<p>Upon reviewing the event logs, each time the cluster was failed over, each missing share was logging the following event:</p>
<pre>Log Name: System
Source: Microsoft-Windows-FailoverClustering
Date: xx/xx/xxxx 08:00:27
Event ID: 1068
Task Category: File Server Resource
Level: Warning
Keywords:
User: SYSTEM
Computer: XXXXXXXXXXX.Domain.com
Description:
Cluster file share resource 'File Server FileServer' cannot be brought online. Creation of file share 'Vedeni' (scoped to network name Fileserver) failed due to error '5'. This operation will be automatically retried.</pre>
<p>Upon reviewing the share permissions, an over zealous administrator had trimmed the NTFS permissions, removing the local system account. Upon each cluster resource coming online, the cluster uses the local system account to enumerate the shares and present them. Remove this account and your shares wont come online!</p>
<p>This  account doesnt need to be on every folder, just each folder a share is based on. E.g. if you share d:sharefinance as serverfinance, only the finance folder needs access granted to the system account.</p>
<p><a href="/wp-content/uploads/2012/01/perms.png"><img class="aligncenter size-full wp-image-1275" title="perms" src="/wp-content/uploads/2012/01/perms.png" alt="" width="362" height="149" /></a></p>
<p>To resolve, configure the system account to have access to the folder on &#8220;this folder only&#8221; then restart the file server resource. The resource will come on-line and your shares will be available again!</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2012/01/the-curious-case-of-missing-file-shares-on-a-microsoft-file-server-cluster/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to monitor a server reboot</title>
		<link>http://andrewmorgan.ie/2008/09/how-to-monitor-a-server-reboot/</link>
		<comments>http://andrewmorgan.ie/2008/09/how-to-monitor-a-server-reboot/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 20:19:42 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Server]]></category>

		<guid isPermaLink="false">http://andymorgan.wordpress.com/?p=116</guid>
		<description><![CDATA[Often when restarting a server its nice to get a complete timeline of when the server went down and subsequently comes back up. I found this script a while back but found it lacked the later port 3389 to enable remote desktop again. I editted the following script from eric and have been using it for a very long time now. http://www.ericwoodford.com/use_ping_to_notify_when_server_reboots I have modified it slightly to include a program called portqry, when a server is restarted it monitors [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="/wp-content/uploads/2008/09/serverrebootstall.jpg"><img class="size-thumbnail wp-image-117 alignright" title="serverrebootstall" src="/wp-content/uploads/2008/09/serverrebootstall.jpg?w=128" alt="" width="128" height="96" /></a></p>
<p>Often when restarting a server its nice to get a complete timeline of when the server went down and subsequently comes back up. I found this script a while back but found it lacked the later port 3389 to enable remote desktop again. I editted the following script from eric and have been using it for a very long time now.</p>
<p>http://www.ericwoodford.com/use_ping_to_notify_when_server_reboots</p>
<p>I have modified it slightly to include a program called portqry, when a server is restarted it monitors ping responses until the server goes down. It then continually pings the server until it gets a response. Once a responce on icmp is received it will query port 3389 (remote desktop) until it gets a response indicating the server is now ready to be logged into again.</p>
<p>you can either type rebooter &#8220;servername&#8221; or simply type rebooter and the program will ask you for the servers name.</p>
<p>After the jump is the code, and the zip file i have uploaded packaging it all together.</p>
<p><span id="more-116"></span></p>
<p>The script is available here with all the neccessary batches/programs, best to extract them to your %windir%system32 where they can be accessed from cmd.</p>
<p>http://www.4shared.com/file/64988601/c29bd123/rebooter.html</p>
<pre>echo off
 CLS
 Set A=0
 Set ServerName=%1
if not '%1'=='' goto :Pass1
 Set /p ServerName=[What is the server name?]
 if not '%ServerName%'=='' goto :Pass1
 echo Failed to get Server name..
 Goto :End
:Pass1
 Title Checking %servername%
 Echo Checking Server %ServerName% for response
 echo Check # _
 :Pass1a
 ping %ServerName% &gt; %servername%-results.txt
 find /C "Request timed out" %servername%-results.txt &gt; %servername%-fresults.txt
for /F "skip=1 tokens=1,2 delims=:" %%a in (%servername%-fresults.txt) DO (
 if NOT "%%b"==" 0" goto :TimedOut
 cls
 Echo Checking Server %ServerName% for response
 echo Check # %A%
 Set /A A+=1
 Goto :Pass1a
 )
 :TimedOut
 Set DownTime=%TIME%
 Title %servername% DOWN
 Echo Server Down %DownTIME% Passes: %A%
 Set B=0
 :Pass2
 ping %ServerName% &gt; %servername%-results.txt
 find /C "Request timed out" %servername%-results.txt &gt; %servername%-fresults.txt
 for /F "skip=1 tokens=1,2 delims=:" %%a in (%servername%-fresults.txt) DO (
 if "%%b"==" 0" set uptime=%time% &amp; set c=0 &amp; goto :BackUp
 CLS
 Echo Checking Server %ServerName% for response
 echo Check # %A% - Server Down: %DownTime%
 Echo Waiting For Server to come up: %B%
 Set /A B+=1
 Goto :Pass2
 )
:BackUp
 Title %servername% Pinging
 cls
 Echo Checking Server %ServerName% for response
 echo Check # %A% - Server Down: %DownTime%
 echo Server Pinging Again: %uptime% - Passes: %B%
 Echo Checking rdp port:
 portqry -n %servername% -q -e 3389
 Set /A C+=1
 if %errorlevel% NEQ 0 goto :backup
 del %servername%-fresults.txt
 del %servername%-results.txt
 cls
 Title %servername% UP
 Echo Checking Server %ServerName% for response
 echo Check # %A% - Server Down: %DownTime%
 echo Server Pinging Again: %uptime% - Passes: %B%
 echo RDP available @ %time% - Passes: %C%
 @echo.
 Echo Server down @ %downtime% Service restored @ %time%
 pause
 :End</pre>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2008/09/how-to-monitor-a-server-reboot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Free Disk Space Report:</title>
		<link>http://andrewmorgan.ie/2008/05/free-space-report/</link>
		<comments>http://andrewmorgan.ie/2008/05/free-space-report/#comments</comments>
		<pubDate>Fri, 02 May 2008 10:45:48 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[VB Scripting]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[FileServer]]></category>
		<category><![CDATA[Free space]]></category>
		<category><![CDATA[Report]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Server]]></category>

		<guid isPermaLink="false">http://joekickass.wordpress.com/?p=51</guid>
		<description><![CDATA[Whether its for daily checks or a for a once off report this handy little script allows you to connect to as many servers as you like, query all local drives, report the capacity of the drives and the free space available. It writes all this information to a snazzy HTML file that is saved on the local disk. This is a vbs file and uses a servers.txt (keep the txt file in the same location as the script) file [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img class="alignright" src="/wp-content/uploads/2008/07/images.jpg?w=144&amp;h=108&amp;h=108" alt="" width="144" height="108" />Whether its for daily checks or a for a once off report this handy little script allows you to connect to as many servers as you like, query all local drives, report the capacity of the drives and the free space available. It writes all this information to a snazzy HTML file that is saved on the local disk.</p>
<p>This is a vbs file and uses a servers.txt (keep the txt file in the same location as the script) file as a reference for each of the servers you wish to connect to. I&#8217;ve tested this on up to 30 servers at a time with flawless output. This script can be run as a schedueled task and accross psexec. Just one point to note, if it is being executed from a UNC path, map the drive first or it will fail to lookup servers.txt</p>
<p>I use this script as a daily check to check up on all the file servers and exchange servers in the morning.</p>
<p>Heres an example of the html file you are finished with.</p>
<h1>Server Utilization Report</h1>
<p>Server1 Drive Utilization</p>
<hr />
<table border="0" cellpadding="5">
<tbody>
<tr>
<td>C:</td>
<td>Size: 20,003 MB</td>
<td>Free: 8,791 MB</td>
<td><strong><span style="font-size:xx-small;color:#008000;">||||||||||||||||||||||||||||||||||||||||||||</span></strong></td>
<td>43.95% Free</td>
</tr>
<tr>
<td>E:</td>
<td>Size: 10,000 MB</td>
<td>Free: 3,715 MB</td>
<td><strong><span style="font-size:xx-small;color:#008000;">|||||||||||||||||||||||||||||||||||||</span></strong></td>
<td>37.15% Free</td>
</tr>
</tbody>
</table>
<p><strong><em>Created 26/02/2008 12:14:12 by morgan_a</em></strong></p>
<p>For the code, click more&#8230;</p>
<p><span id="more-3072"></span></p>
<p>&#8216;Andrew Morgan February 2008<br />
&#8216;connects to a device and lists all capacity &amp; free space</p>
<p>Dim objService,objLocator<br />
Dim objFSO, objOutFile,objFile1<br />
Dim objNetwork</p>
<p>&#8216;Get Date Vars<br />
strMonth = Month(Date)<br />
strDay = Day(Date)<br />
strYear = Right(Year(Date),2)</p>
<p>On Error Resume Next</p>
<p>&#8216;Location of HTML file that will be created (dont use network shares unless drive is mapped)<br />
htmFile=&#8221;c:&#8221; &amp; strMonth &amp; &#8220;-&#8221; &amp; strDay &amp; &#8220;-&#8221; &amp; strYear &amp; &#8220;.htm&#8221;</p>
<p>&#8216;Name of servers text file (must be kept in the same directory as the script)<br />
serverlist=&#8221;servers.txt&#8221;</p>
<p>Const myGreen=&#8221;008000&#8243;<br />
Const myRed=&#8221;FF0000&#8243;<br />
Const myYellow=&#8221;FFD700&#8243;</p>
<p>set objNetwork=CreateObject(&#8220;wscript.network&#8221;)<br />
Set objFSO=CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<br />
Set objOutFile=objFSO.CreateTextFile(htmFile)<br />
Set objFile1=objFSO.OpenTextFile(serverlist,1)</p>
<p>&#8216;Write Lead in of htm file<br />
&#8216;Change the next line to change the header<br />
objOutfile.WriteLine &#8220;&lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;Server Logical Drive Utilization&lt;/TITLE&gt;&lt;/HEAD&gt;&#8221;<br />
&#8216;objOutfile.WriteLine &#8220;&lt;BODY BGCOLOR=&#8221; &amp; CHR(34) &amp; &#8220;FFFFF&#8221; &amp; CHR(34)&amp; &#8220;&gt;&#8221;<br />
objOutfile.WriteLine &#8220;&lt;BODY BGCOLOR=FFFFF&gt;&#8221;<br />
objOutfile.WriteLine &#8220;&lt;H1&gt;Server Utilization Report&lt;/H1&gt;&lt;/P&gt;&#8221;</p>
<p>Do While objFile1.AtEndOfStream&lt;&gt;True<br />
strServer=objFile1.ReadLine</p>
<p>If strServer&lt;&gt;&#8221;&#8221; Then<br />
&#8216;reinitialize<br />
PerFree=&#8221;&#8221;<br />
Graph=&#8221;&#8221;<br />
Size=&#8221;&#8221;<br />
Free=&#8221;&#8221;</p>
<p>objOutfile.WriteLine &#8220;&lt;BR&gt;&#8221; &amp; UCASE(strServer) &amp; &#8221; Drive Utilization&lt;BR&gt;&lt;HR&gt;&#8221;</p>
<p>&#8216;Create locator<br />
Set objLocator = CreateObject(&#8220;WbemScripting.SWbemLocator&#8221;)<br />
If Err.Number then<br />
objOutfile.WriteLine &#8220;Error &#8221; &amp; err.number &amp; &#8221; [0x&#8221; &amp; CStr(Hex(Err.Number)) &amp; &#8220;] occurred in creating a locator object.&lt;BR&gt;&#8221;<br />
If Err.Description &lt;&gt; &#8220;&#8221; Then<br />
objOutfile.WriteLine &#8220;Error description: &#8221; &amp; Err.Description &amp; &#8220;.&lt;/p&gt;&#8221;<br />
End If<br />
Err.Clear<br />
End If</p>
<p>&#8216;Connect to the namespace which is either local or remote<br />
&#8216;Uncomment next line for debugging<br />
&#8216;wscript.echo &#8220;Connecting to &#8221; &amp; &#8220;(&#8220;&amp;strServer&amp;&#8221;,rootcimv2)&#8221;</p>
<p>Set objService = objLocator.ConnectServer (strServer,&#8221;rootcimv2&#8243;)<br />
ObjService.Security_.impersonationlevel = 3<br />
If Err.Number then<br />
objOutfile.WriteLine &#8220;Error &#8221; &amp; err.number &amp; &#8221; [0x&#8221; &amp; CStr(Hex(Err.Number)) &amp;&#8221;] occurred in connecting to server &#8221; &amp; UCASE(strServer) &amp; &#8220;.&lt;BR&gt;&#8221;<br />
objOutfile.WriteLine &#8220;Make sure you are using valid credentials that have administrative rights on this server.&lt;/P&gt;&#8221;<br />
If Err.Description &lt;&gt; &#8220;&#8221; Then<br />
objOutfile.WriteLine &#8220;Error description: &#8221; &amp; Err.Description &amp; &#8220;.&lt;/P&gt;&#8221;<br />
End If<br />
Err.Clear<br />
Else</p>
<p>objOutfile.WriteLine &#8220;&lt;Table Border=0 CellPadding=5&gt;&#8221;<br />
For Each item In objService.InstancesOf(&#8220;Win32_LogicalDisk&#8221;)<br />
If item.DriveType=3 Then &#8216;get local drives only<br />
PerFree=FormatPercent(item.FreeSpace/item.Size,2)<br />
Graph=FormatNumber((item.Freespace/1048576)/(item.Size/1048576),2)*100<br />
Size=FormatNumber(item.Size/1048576,0) &amp; &#8221; MB&#8221;<br />
Free=FormatNumber(item.FreeSpace/1048576,0) &amp; &#8221; MB&#8221;</p>
<p>objOutfile.WriteLine &#8220;&lt;TR&gt;&#8221;<br />
objOutfile.WriteLine &#8220;&lt;TD&gt;&#8221; &amp;item.DeviceID &amp; &#8221; &lt;/TD&gt;&#8221;<br />
objOutfile.WriteLine &#8220;&lt;TD&gt;Size: &#8221; &amp; Size &amp; &#8220;&lt;/TD&gt;&#8221;<br />
objOutfile.WriteLine &#8220;&lt;TD&gt;Free: &#8221; &amp; Free &amp; &#8220;&lt;/TD&gt;&#8221;<br />
objOutfile.WriteLine &#8220;&lt;TD&gt;&lt;B&gt;&lt;Font Size=+1 Color=&#8221; &amp; GraphColor(graph) &amp; &#8220;&gt;&#8221; &amp; String(Graph,&#8221;|&#8221;) &amp; &#8220;&lt;/Font&gt;&lt;/B&gt;&lt;/TD&gt;&#8221;<br />
objOutfile.WriteLine &#8220;&lt;TD&gt;&#8221; &amp; PerFree &amp; &#8221; Free&lt;/TD&gt;&lt;/TR&gt;&#8221;<br />
End If<br />
Next<br />
objOutfile.WriteLine &#8220;&lt;/Table&gt;&#8221;<br />
End If<br />
End If<br />
Loop<br />
objFile1.Close</p>
<p>objOutfile.WriteLine(&#8220;&lt;/P&gt;&lt;Font Size=-1&gt;&lt;B&gt;&lt;I&gt; Created &#8221; &amp; NOW &amp; &#8221; by &#8221; &amp; objNetwork.UserName &amp; &#8220;&lt;/I&gt;&lt;/B&gt;&lt;/Font&gt;&#8221;)<br />
objOutfile.WriteLine(&#8220;&lt;/BODY&gt;&lt;/HTML&gt;&#8221;)<br />
objOutfile.Close<br />
&#8216;commented echo back<br />
&#8216;wscript.Echo VBCRLF &amp; &#8220;See &#8221; &amp; htmfile &amp; &#8221; for results&#8221;<br />
Function GraphColor(graph)<br />
On Error Resume Next<br />
If Graph &gt; 30 Then<br />
GraphColor=myGreen<br />
Exit Function<br />
End If<br />
If Graph &lt; 10 Then<br />
GraphColor=myRed<br />
Else<br />
GraphColor=myYellow<br />
End If<br />
End Function<br />
Sub CheckResponse(response)<br />
If response=&#8221;&#8221; Then<br />
wscript.Echo &#8220;You didn&#8217;t enter anything in the last input box or you cancelled the script.&#8221;<br />
wscript.Quit<br />
End If<br />
End Sub</p>
<p>&#8216;EOF</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2008/05/free-space-report/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
