<?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>The VBScript Network and Systems Administrator&#039;s Cafe &#187; Disk usage</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/tag/disk-usage/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator</link>
	<description></description>
	<lastBuildDate>Tue, 11 Oct 2011 18:36:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Getting disk usage data with the filesystem object and the Excel.Application object in VBScript</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/getting-disk-usage-data-with-the-filesystem-object-and-the-excelapplication-object-in-vbscript/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/getting-disk-usage-data-with-the-filesystem-object-and-the-excelapplication-object-in-vbscript/#comments</comments>
		<pubDate>Wed, 14 May 2008 20:58:25 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[Disk usage]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Excel.Application]]></category>
		<category><![CDATA[File System Object]]></category>
		<category><![CDATA[FSO]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[Scripting.FileSystemObject]]></category>
		<category><![CDATA[system trending]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/getting-disk-usage-data-with-the-filesystem-object-and-the-excelapplication-object-in-vbscript/</guid>
		<description><![CDATA[In my previous posting, entitled Working with the Excel.Application object in VBScript to create Excel Spreadsheets, we worked with excel in VBScript to create a excel spreadsheet. The spreadsheet wasn&#8217;t going to win any awards for complexity or usefulness, but none the less it was a spreadsheet&#8211; and more importantly it was generated by a [...]]]></description>
				<content:encoded><![CDATA[<p>In my previous posting, entitled <a rel="bookmark" href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/working-with-the-excelapplication-object-in-vbscript-to-create-excel-spreadsheets/" title="Permanent Link to Working with the Excel.Application object in vbscript to create Excel Spreadsheets">Working with the Excel.Application object in VBScript to create Excel Spreadsheets</a>, we worked with excel in VBScript to create a excel spreadsheet. The spreadsheet wasn&#8217;t going to win any awards for complexity or usefulness, but none the less it was a spreadsheet&#8211; and more importantly it was generated by a script! I also promised to bring you a script to help you chart disk space usage in my next posting in the series. This posting is the fulfilment of that promise! Also, please note that you will need Excel installed where the script runs for this script to operate correctly&#8211; but it does not need to be installed on the system you are pulling disk free space information from since I used the WMI object instead of the filesystem object.</p>
<p>The script below uses WMI&#8217;s <a target="_blank" href="http://msdn.microsoft.com/en-us/library/aa394173.aspx">Win32_LogicalDisk</a> class to grab the drives in the target system, specifically the drive you specify through the use of a where clause in the SQL statement that pulls back the WMI data. (Through the &#8220;where deviceid like&#8221; section of the SQL statement in the code)</p>
<p> Also, I didn&#8217;t put a lot of effort into the code where the for/next loop is that loops through getting and saving the free space because I didn&#8217;t want to create a lot of extra complexity and wanted to create a script that would run through to completion pretty quickly. Currently, the script takes 10 minutes to complete. To test the script while it&#8217;s running, just create files in a folder and delete them a number of times. I created a 10Mb and 20Mb file and made a series of copy/pastes during execution&#8211; with a smattering of deletes in the mix.</p>
<p>For further customization, you can look at the code from the posting I wrote a while back <a rel="bookmark" href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/reporting-cpu-usage-by-saving-it-to-a-file-with-the-vbscript-filesystem-object/" title="Permanent Link to Reporting CPU usage by saving it to a file with the VBScript filesystem object">Reporting CPU usage by saving it to a file with the VBScript filesystem object</a> to get a good feel for how to modify the loop to get what you want. In essence, change the number 2 in &#8220;Wscript.Sleep 2&#8243; to a lager number to get a bigger gap between samples and change the 300 in the &#8220;<font color="#000000">For x = 1 to 300&#8243; line to a larger number to get a longer sample period.</font></p>
<p>Here is the code:<br />
<font color="#0000ff">Dim Freespace, CurrentRow, ServerName<br />
Const xlSaveChanges = 1</font></p>
<p><font color="#0000ff">&#8216;the first row in excel is 1 (not 0)<br />
CurrentRow = 1<br />
ServerName=&#8221;.&#8221;</font></p>
<p><font color="#0000ff">Set objExcel = CreateObject(&#8220;Excel.Application&#8221;)<br />
objExcel.Visible = False<br />
objExcel.Workbooks.Add<br />
For x = 1 to 300 &#8216; change 300 to increase your sample duration<br />
     objExcel.Cells(CurrentRow, 1).Value = GetFreeSpace(&#8220;C:&#8221;,ServerName)<br />
     CurrentRow = CurrentRow + 1<br />
     Wscript.sleep 2 &#8216;change this to spread out your samples<br />
next</font></p>
<p><font color="#0000ff">objExcel.ActiveWorkbook.SaveAs (&#8220;C:\excelvbscript.xls&#8221;)<br />
objExcel.Quit</font><br />
<font color="#0000ff">Function GetFreeSpace(Drive,strComputer)<br />
     Set objWMIService = GetObject(&#8220;winmgmts:{impersonationLevel=impersonate}!\\&#8221;_<br />
         &amp; strComputer &amp; &#8220;\root\cimv2&#8243;)<br />
     Set colDisks = objWMIService.ExecQuery (&#8220;Select * from Win32_LogicalDisk where deviceid like &#8220;_<br />
         &amp;chr(34) &amp; Drive &amp; chr(34))<br />
     For Each objDisk in colDisks<br />
         GetFreeSpace = (objDisk.freespace/1024)/1024 &#8216; get MB free<br />
     Next<br />
End Function</font></p>
<p><font color="#0000ff"><font color="#000000">As always, this code works perfectly. However, sometimes the formatting of the blog breaks the code if you copy and paste it into your editor. So, if you’d like to not type or troubleshoot any syntax errors due to the copy and paste problems– I’ve provided the code for download, plus example output files  from my final tests for you. You’ll find the code and other files available for download from my website’s (<a href="http://www.websystemsadministration.com/">www.websystemsadministration.com</a>) File Depot under the <font color="#0000ff"><em>ITKE Blog Scripts</em></font> category.<font color="#0000ff"> </font><font color="#0000ff"><font color="#0000ff"><font color="#000000">Enjoy and happy scripting!</font></font></font></font></font></p>
<p><!--a href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/pinging-a-remote-computer-from-another-remote-computer-using-the-wmi-win32_pingstatus-class/trackback/" title="Trackback URL"&gt;Trackback URL</a>&#8211;></p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/getting-disk-usage-data-with-the-filesystem-object-and-the-excelapplication-object-in-vbscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
