<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/wordpress-mu-1.2.1" -->
<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/"
	>

<channel>
	<title>The VBScript Network and Systems Administrator's Cafe</title>
	<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator</link>
	<description></description>
	<pubDate>Wed, 14 May 2008 21:12:42 +0000</pubDate>
	<generator>http://wordpress.org/?v=wordpress-mu-1.2.1</generator>
	<language>en</language>
			<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[system trending]]></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[VBScript]]></category>

		<category><![CDATA[Documentation]]></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 diskspace 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 teh 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(&#8221;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(&#8221;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 (&#8221;C:\excelvbscript.xls&#8221;)<br />
objExcel.Quit</font><br />
<font color="#0000ff">Function GetFreeSpace(Drive,strComputer)<br />
     Set objWMIService = GetObject(&#8221;winmgmts:{impersonationLevel=impersonate}!\\&#8221;_<br />
         &amp; strComputer &amp; &#8220;\root\cimv2&#8243;)<br />
     Set colDisks = objWMIService.ExecQuery (&#8221;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>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&#8211; 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.webstemsadministration.com)/">www.webstemsadministration.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></p>
]]></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>
		</item>
		<item>
		<title>VbScript Statements: Explaination of Select &#8230; Case</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/vbscript-statements-explaination-of-select-case/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/vbscript-statements-explaination-of-select-case/#comments</comments>
		<pubDate>Fri, 09 May 2008 17:54:17 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
		
		<category><![CDATA[vbscriptstatements]]></category>

		<category><![CDATA[VBScript Statements]]></category>

		<category><![CDATA[VBScript]]></category>

		<category><![CDATA[Functions]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/vbscript-statements-explaination-of-select-case/</guid>
		<description><![CDATA[The Select &#8230; Case Vbscript statement is a very powerful way to easily preform specific actions based on a comparison of a variable to a series of cases you specify, plus it allows for the fact that NONE of the cases apply with an optional case else condition. The Select Case statement is often a [...]]]></description>
			<content:encoded><![CDATA[<p>The Select &#8230; Case Vbscript statement is a very powerful way to easily preform specific actions based on a comparison of a variable to a series of cases you specify, plus it allows for the fact that <strong><em>NONE</em></strong> of the cases apply with an optional <strong>case else</strong> condition. The Select Case statement is often a better solution then a <strong>if&#8230;Then&#8230;Else if</strong> when you have more than 2 conditions that could apply.</p>
<p>Consider the following code snippet to check if a number is positive or negative:</p>
<p>Function TestNumber(Number)  </p>
<p>    Select case Number<br />
        Case Number &gt; 0<br />
             TestNumber = &#8220;Positive&#8221;<br />
        Case Number &lt; 0<br />
             TestNumber = &#8220;Negative&#8221;<br />
        Case Else<br />
             TestNumber = &#8220;Zero&#8221;<br />
    End Select</p>
]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/vbscript-statements-explaination-of-select-case/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Working with the Excel.Application object in vbscript to create Excel Spreadsheets</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/working-with-the-excelapplication-object-in-vbscript-to-create-excel-spreadsheets/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/working-with-the-excelapplication-object-in-vbscript-to-create-excel-spreadsheets/#comments</comments>
		<pubDate>Fri, 09 May 2008 16:28:10 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
		
		<category><![CDATA[Excel.Application]]></category>

		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/working-with-the-excelapplication-object-in-vbscript-to-create-excel-spreadsheets/</guid>
		<description><![CDATA[In my previous two postings we discussed the Microsoft Word.Application object (here and here) to use as a logging mechanism and as a documentation mechanism for our scripts we&#8217;re writing.
But what about if you wanted to log numbers, like in the performance counter posts I made a few weeks back? I&#8217;ve also seen several questions about how [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous two postings we discussed the Microsoft <em>Word.Application</em> object (<a target="_blank" href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-vbscript-to-create-word-documents-automatically-with-the-wordapplication-object/">here</a> and <a target="_blank" href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/easily-document-group-policy-objects-in-microsoft-word-using-vbscript-with-the-microsoftxmldom-and-wordapplication-objects/">here</a>) to use as a logging mechanism and as a documentation mechanism for our scripts we&#8217;re writing.</p>
<p>But what about if you wanted to log numbers, like in the performance counter posts I made a few weeks back? I&#8217;ve also seen several questions about how to do use excel in vbscript. Well, it&#8217;s super easy, once you get the object understood. The next few postings I&#8217;ll focus on this great way to save data in a format that is easily shareable and can easily be made into pretty pie charts and such for the boss.</p>
<p>First off I&#8217;ll give you a simple example that basically creates the object (not visible), adds a new workbook to it, adds a string to cell 1,1, and finally saves it before it quits. Below is the example code for this scriptlet:</p>
<p><font color="#0000ff">Const xlSaveChanges = 1</font></p>
<p><font color="#0000ff">Set objExcel = CreateObject(&#8221;Excel.Application&#8221;)<br />
objExcel.Visible = False<br />
objExcel.Workbooks.Add<br />
objExcel.Cells(1, 1).Value = &#8220;Test value&#8221;<br />
objExcel.ActiveWorkbook.SaveAs (&#8221;C:\excelvbscript.xls&#8221;)<br />
objExcel.Quit</font></p>
<p>I&#8217;ll dig deeper right after I go back and explain the Select Case statement I used in a previous posting&#8211; which I neglected to mention previously or explain in the posting. (Bad, Jerry, Bad Bad.) Hwever, after that I promis to come back with a more specific example of Excel.Application, but this should give you a little bit to play with in the mean time.</p>
<p>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 XML files and Generated Word Documents for you. You’ll find the code available for download from my website’s (<a href="http://www.webstemsadministration.com)/">www.webstemsadministration.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></p>
<p><!--a href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/easily-document-group-policy-objects-in-microsoft-word-using-vbscript-with-the-microsoftxmldom-and-wordapplication-objects/trackback/" title="Trackback URL"&amp;gt;Trackback URL</a>&#8211;></p>
]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/working-with-the-excelapplication-object-in-vbscript-to-create-excel-spreadsheets/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Easily document group policy objects in Microsoft Word using VBScript with the Microsoft.XMLDOM and Word.Application objects</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/easily-document-group-policy-objects-in-microsoft-word-using-vbscript-with-the-microsoftxmldom-and-wordapplication-objects/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/easily-document-group-policy-objects-in-microsoft-word-using-vbscript-with-the-microsoftxmldom-and-wordapplication-objects/#comments</comments>
		<pubDate>Fri, 02 May 2008 16:15:42 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
		
		<category><![CDATA[Functions]]></category>

		<category><![CDATA[DataManagement]]></category>

		<category><![CDATA[Microsoft.XMLDOM]]></category>

		<category><![CDATA[VBA]]></category>

		<category><![CDATA[VBScript]]></category>

		<category><![CDATA[XML]]></category>

		<category><![CDATA[Word.application]]></category>

		<category><![CDATA[Documentation]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/easily-document-group-policy-objects-in-microsoft-word-using-vbscript-with-the-microsoftxmldom-and-wordapplication-objects/</guid>
		<description><![CDATA[OK, here is the posting I hinted at in  my previous posting this week entitiled, Using Vbscript to create Word documents automatically with the Word.Application Object. In that posting I mentioned a project where I had to create a ton of documentation&#8230; but I didn&#8217;t say what it was that I had to document. Yeap, you guessed [...]]]></description>
			<content:encoded><![CDATA[<p>OK, here is the posting I hinted at in  my previous posting this week entitiled, <a rel="bookmark" href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-vbscript-to-create-word-documents-automatically-with-the-wordapplication-object/" title="Permanent Link to Using Vbscript to create Word documents automatically with the Word.Application Object">Using Vbscript to create Word documents automatically with the Word.Application Object</a>. In that posting I mentioned a project where I had to create a ton of documentation&#8230; but I didn&#8217;t say what it was that I had to document. Yeap, you guessed it from this article&#8217;s title&#8230; <strong><em>Group Policy Settings!</em></strong> I had to document settings in a series of policies I was proposing we implement at my employer. Here is the scenario:</p>
<p>I was asked &#8220;Can you document all the settings you are proposing in the new policies for the other members of IT? Also, Can you document the name of the setting, what you want it to be and what options are available to change it to? Oh, and what each value means when you set it?&#8230;. Do you think you&#8217;ll have time to also let us know for each setting what the supported or intended OS version is for the setting? I need it by Friday.&#8221;</p>
<p>Now, much like you might do, I said &#8220;I&#8217;ll try.&#8221; and mumbled under my breath later &#8220;If you bring me a pound of Lead I&#8217;ll turn it to Gold too!&#8221;&#8230; None the less, after my initial pitty party, I began looking at the Information available to me in the Group Policy Management Console (Available <a target="_blank" href="http://www.microsoft.com/downloads/details.aspx?FamilyId=0A6D4C24-8CBD-4B35-9272-DD3CBFC81887&amp;displaylang=en">here</a> if you don&#8217;t have it already.), much to my surprise I found almost everything I needed when I looked at the individual settings&#8230; it just wasn&#8217;t in a format I could show to people or they could read easily. So I set out to try and copy and paste the information into word&#8230; for 20 seconds&#8230; and realized this is way to much work! And what do I always say??????   <strong>Be Lazy!</strong></p>
<p>Now I looked at the options available to me on exporting the file and CSV was one of them, but unfortunately all the relationships were lost and I couldn&#8217;t make heads or tails of how to cobble it back together in a meaningful way after the export. Then I noticed XML and remembered my last post on Microsoft.XMLDOM (<a rel="bookmark" href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-xml-in-vbscript-via-microsoftxmldom-to-work-with-data-feeds/" title="Permanent Link to Using XML in vbscript via Microsoft.XMLDOM to work with data feeds">Using XML in vbscript via Microsoft.XMLDOM to work with data feeds</a>) and thought, I really need to get back to that&#8230; so here we are!</p>
<p>First, Just like my last post&#8211; you&#8217;ll need Microsoft Word installed where you run this script for it to operate. Then you&#8217;ll need to use The Group Policy Management console to export the policy settings to XML. (hover over the icons along the top, it&#8217;s the one with the icon that looks like a page of paper with an arrow pointing right, one of the save as options is XML.) Save this file into the location where the script is located (I recommend a descriptive name, because it will be the heading for your document.) and with a single edit of the script you will have a word doc on the root of your C: drive with the same name&#8212; only documented in Word!</p>
<p>The script basically opens and reads in the XML Document and creates a Word.Application object to create a Microsoft Word Document at the root of the C: Drive, then writes formatted text to the document to make the data in the XML readable. But, enough of a introduction! On to the script! Here is the script:</p>
<p><font color="#0000ff"> set xmlDoc=CreateObject(&#8221;Microsoft.XMLDOM&#8221;)<br />
Set objWord = CreateObject(&#8221;Word.Application&#8221;)<br />
Set objDoc = objWord.Documents.Add()<br />
Set objSelection = objWord.Selection</font></p>
<p><font color="#0000ff">&#8216;This is the actual name of the XML document minus the path and the &#8220;.XML&#8221; extension, it becomes the word doc header</font><br />
<font color="#0000ff">xmlfile = &#8220;Locked Down Desktop Policy&#8221;</font></p>
<p><font color="#0000ff">objSelection.Font.Name = &#8220;Arial&#8221;<br />
objSelection.Font.Size = &#8220;18&#8243;<br />
objSelection.Font.Bold = True<br />
objSelection.TypeText xmlfile &amp; VbCrLf</font></p>
<p><font color="#0000ff">objSelection.Font.Bold = False<br />
objSelection.Font.Size = &#8220;10&#8243;</font></p>
<p><font color="#0000ff">xmlDoc.async=&#8221;false&#8221;<br />
xmlDoc.load(xmlfile &amp;&#8221;.xml&#8221;)<br />
for each x in xmlDoc.documentElement.childNodes<br />
If x.nodename = &#8220;Computer&#8221; or x.nodename = &#8220;User&#8221; Then<br />
For Each y In x.childnodes<br />
if y.Nodename = &#8220;ExtensionData&#8221; then<br />
For Each z In y.childnodes<br />
If z.Nodename = &#8220;Extension&#8221; Then<br />
For Each setting In z.childnodes<br />
objSelection.TypeText &#8220;______________________________________&#8221; &amp; vbCr<br />
DocumentPolicy(Setting)<br />
Next<br />
End if<br />
Next<br />
End if<br />
Next<br />
End If<br />
Next<br />
objDoc.SaveAs(&#8221;C:\&#8221; &amp; xmlfile &amp; &#8220;.doc&#8221;)<br />
objWord.Quit</font><br />
<font color="#0000ff">Function DocumentPolicy(Setting)<br />
</font><font color="#0000ff">&#8216;this function basically cleans up the headers of the word document, so they are more human readable<br />
Select Case setting.nodename<br />
Case &#8220;q1:Policy&#8221;<br />
replacestr = &#8220;q1:&#8221;<br />
Case &#8220;q1:DropDownList&#8221;<br />
replacestr = &#8220;q1:&#8221;<br />
Case &#8220;q1:Name&#8221;<br />
replacestr = &#8220;q1:&#8221;<br />
Case &#8220;q1:Value&#8221;<br />
replacestr = &#8220;q1:&#8221;<br />
Case &#8220;q1:State&#8221;<br />
replacestr = &#8220;q1:&#8221;<br />
Case &#8220;q2:Audit&#8221;<br />
replacestr = &#8220;q2:&#8221;<br />
Case &#8220;q2:SecurityOptions&#8221;<br />
replacestr = &#8220;q2:&#8221;<br />
Case &#8220;q2:EventLog&#8221;<br />
replacestr = &#8220;q2:&#8221;<br />
Case &#8220;q2:RestrictedGroups&#8221;<br />
replacestr = &#8220;q2:&#8221;<br />
Case &#8220;q2:File&#8221;<br />
replacestr = &#8220;q2:&#8221;<br />
Case &#8220;q2:Display&#8221;<br />
replacestr = &#8220;q2:&#8221;<br />
Case &#8220;q3:General&#8221;<br />
replacestr = &#8220;q3:&#8221;<br />
Case &#8220;q3:HashRule&#8221;<br />
replacestr = &#8220;q3:&#8221;<br />
Case &#8220;q3:PathRule&#8221;<br />
replacestr = &#8220;q3:&#8221;<br />
Case &#8220;q3:InternetZoneRule&#8221;<br />
replacestr = &#8220;q3:&#8221;<br />
Case &#8220;q4:AutoEnrollmentSettings&#8221;<br />
replacestr = &#8220;q4:&#8221;<br />
Case &#8220;q4:AutoEnrollmentSettings&#8221;<br />
replacestr = &#8220;q4:&#8221;<br />
Case &#8220;q4:RootCertificateSettings&#8221;<br />
replacestr = &#8220;q4:&#8221;<br />
Case &#8220;q4:EFSSettings&#8221;<br />
replacestr = &#8220;q4:&#8221;<br />
Case &#8220;q5:PreferenceMode&#8221;<br />
replacestr = &#8220;q5:&#8221;<br />
Case &#8220;q2:PreferenceMode&#8221;<br />
replacestr = &#8220;q2:&#8221;<br />
Case &#8220;q2:ProxySettings&#8221;<br />
replacestr = &#8220;q2:&#8221;<br />
Case &#8220;q2:UseSameProxy:&#8221;<br />
replacestr = &#8220;q2:&#8221;<br />
Case &#8220;q2:HTTP:&#8221;<br />
replacestr = &#8220;q2:&#8221;<br />
Case &#8220;q2:NoProxyIntranet:&#8221;<br />
replacestr = &#8220;q2:&#8221;</font><font color="#0000ff">End Select<br />
objSelection.Font.Bold = True<br />
objSelection.TypeText VbCrLf &amp; replace(setting.nodename, replacestr,&#8221;") &amp; VbCrLf<br />
objSelection.Font.Bold = False<br />
For Each Value In Setting.Childnodes<br />
NodeName = replace(Value.nodename,replacestr,&#8221;")<br />
If NodeName = &#8220;Explain&#8221; Then<br />
objSelection.Font.Bold = True<br />
objSelection.TypeText Nodename &amp; &#8220;: &#8221; &amp; vbcrlf<br />
objSelection.Font.Bold = False<br />
objSelection.TypeText vbTab &amp; replace(value.text,&#8221;\n\n&#8221;, VbCrLf &amp; VbCrLf &amp; vbTab )&amp; vbcrlf<br />
Else<br />
objSelection.Font.Bold = True<br />
objSelection.TypeText Nodename &amp; &#8220;: &#8220;<br />
objSelection.Font.Bold = False<br />
objSelection.TypeText vbtab &amp; value.text &amp; vbcrlf<br />
End if<br />
Next<br />
If isnull(Setting.childnodes) Then<br />
For Each node In Setting.childnodes<br />
DocumentPolicy(node)<br />
next<br />
End if<br />
objSelection.TypeText VbCrLf</p>
<p></font><font color="#0000ff">End Function</font></p>
<p>Now, when you run this script agains your export there may be some XML tags I didn&#8217;t notice because a setting you set is one I didn&#8217;t set. Any time you see them in the document you can add a new <strong>Case</strong> statement in the select case followed by setting the <em>replacestr</em> to the string you want to replace with a null. The lines I&#8217;m talking about look similar to this:</p>
<p><font color="#0000ff">  Case &#8220;q2:xxxxxxxx&#8221;<br />
replacestr = &#8220;q2:&#8221;</font></p>
<p>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 XML files and Generated Word Documents for you. You&#8217;ll find the code available for download from my website’s (<a href="http://www.webstemsadministration.com)/">www.webstemsadministration.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></p>
]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/easily-document-group-policy-objects-in-microsoft-word-using-vbscript-with-the-microsoftxmldom-and-wordapplication-objects/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Vbscript to create Word documents automatically with the Word.Application Object</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-vbscript-to-create-word-documents-automatically-with-the-wordapplication-object/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-vbscript-to-create-word-documents-automatically-with-the-wordapplication-object/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 14:20:59 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
		
		<category><![CDATA[Word.application]]></category>

		<category><![CDATA[VBA]]></category>

		<category><![CDATA[DataManagement]]></category>

		<category><![CDATA[VBScript]]></category>

		<category><![CDATA[Developer documentation]]></category>

		<category><![CDATA[Documentation]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-vbscript-to-create-word-documents-automatically-with-the-wordapplication-object/</guid>
		<description><![CDATA[I recently had a project that required me to create a ton of documentation from data that was already stored in files elsewhere on the network&#8211; just not in the format that was required and readable by every day people within IT. (Basically, non-administrators) This project would have required a TON of copy and paste [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had a project that required me to create a ton of documentation from data that was already stored in files elsewhere on the network&#8211; just not in the format that was required and readable by every day people within IT. (Basically, non-administrators) This project would have required a TON of copy and paste operations or a whole lot MORE reworking of a document, plus I was on a tight deadline. So I decided to use a little VBA (Visual Basic for Applications) knowledge I had picked up in the past to work with the Microsoft Word Application interface and do the job, with only minor reworking after the fact to really tiddy up the document.</p>
<p>First, let me clarify. Most of my scripts I use here require nothing more than the items I mentioned in my first posting (<a rel="bookmark" href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/getting-started-writing-vbscript-to-administer-a-windows-2000-and-2003-network/" title="Permanent Link to Getting Started Writing VBScript to Administer a Windows 2000 or 2003 Network">Getting Started Writing VBScript to Administer a Windows 2000 or 2003 Network</a>) on this blog&#8230; a Vbscript editor. <em>(Notepad will do&#8230; but you&#8217;ll likely quickly want something a bit more powerful before long.) </em>The scripts I discuss in this series are <strong><em>one exception</em></strong>, for these scripts we discuss in the next few articles we will need to make sure you have Microsoft Word installed where ever you run the script. However, for the purposes of this type of work your workstation should work fine and will likely already have Microsoft word installed! Bonus!</p>
<p>The &#8220;magic&#8221; component we need to call and create an object from is called <em><strong>Word.application</strong>, </em>as you&#8217;ll see below, it&#8217;s pretty easy to create a word document from vbscript and then have autogenerating documentation!</p>
<p>The next sections of code will show you how to do various tasks with in word. Many sections are not scripts on themselves, but infact snippets that could be placed into the first script prior to the remark for testing. The first snippet, creates a word document and saves it to the root of your C: drive. When you run this it will run, but create a blank word document&#8211; much like if you right clicked somewhere and selected <em>New/Microsoftw Word Document.</em> Here are some common tasks in word I use:</p>
<p><strong>Create a new (empty) Word Document and save it to c:\testdoc.doc</strong><br />
<font color="#15326b">Set objWord = CreateObject(&#8221;Word.Application&#8221;)<br />
&#8216;note: if you don&#8217;t want word popping up and displaying as this is built&#8211; set this next line to False</font><font color="#15326b"><br />
objWord.Visible = True<br />
</font><font color="#15326b">Set objDoc = objWord.Documents.Add()<br />
&#8217;save the Word Document<br />
objDoc.SaveAs(&#8221;C:\testdoc.doc&#8221;)<br />
</font></p>
<p><font color="#15326b"><font color="#000000"><strong>Setting the Font type<br />
</strong><font color="#15326b">objSelection.Font.Name = &#8220;Arial&#8221;<br />
</font></font></font></p>
<p><font color="#15326b"><font color="#000000"><strong>Setting the Font Size<br />
</strong><font color="#15326b">objSelection.Font.Size = &#8220;18&#8243;<br />
</font></font></font></p>
<p><font color="#15326b"><font color="#000000"><strong>Adding Text<br />
</strong><font color="#15326b">objSelection.TypeText &#8220;Add your text here&#8221;<br />
objSelection.TypeParagraph()</font></font></font></p>
<p><font color="#15326b"><strong><font color="#000000">Setting the typeface to bold<br />
</font></strong></font><font color="#15326b">objSelection.Font.Bold = True</font></p>
<p><font color="#15326b"><font color="#000000"><strong>Closing the word document (generally done after saving)<br />
</strong><font color="#15326b">objWord.Quit</font></font></font></p>
<p><font size="+0"><font color="#000000">These should get you started playing with Vbscript to create word documents. For more information on working with microsoft word in vbscript look <a target="_blank" href="http://msdn.microsoft.com/en-us/library/78whx7s6(VS.80).aspx">here</a> at Microsoft&#8217;s site, while it&#8217;s not related exactly to vbscript&#8211; it should give you enough information about the interface to get started.</font></font></p>
<p><font size="+0"> Next time, I&#8217;ll share a script to document settings in Group policy with a word document through a combination of using <em>Word.Application</em> and <em>Microsoft.XMLDOM.</em></font></p>
<p>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 for you. From here on out I will make the code available for download from my website’s (<a href="http://www.webstemsadministration.com)/">www.webstemsadministration.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></p>
]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-vbscript-to-create-word-documents-automatically-with-the-wordapplication-object/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How VBScript variable types are represented as binary numbers</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/binary-numbers/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/binary-numbers/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 15:19:20 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
		
		<category><![CDATA[Variable Types]]></category>

		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/binary-numbers/</guid>
		<description><![CDATA[In a previous posting,  Converting variable types in vbscript from one type to another type, I discussed very briefly binary numbers and promised to write another entry with more detail. If you recall we we were discussing the size a number takes up to represent it in binary form.
Everyone is comfortable with the numbers 1 and 0, [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous posting,  <a rel="bookmark" href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/converting-variable-types-in-vbscript-from-one-type-another-type/" title="Permanent Link to Converting variable types in vbscript from one type to another type">Converting variable types in vbscript from one type to another type</a>, I discussed very briefly binary numbers and promised to write another entry with more detail. If you recall we we were discussing the size a number takes up to represent it in binary form.</p>
<p>Everyone is comfortable with the numbers 1 and 0, even in binary. And if you&#8217;re in IT, you&#8217;re probably even comfortable with binary 10, which isn&#8217;t Ten&#8211; it&#8217;s two. Normally we count in tens (with ten digits in each place), but computers count in twos (with only two digits in each place), which is base-2 instead of base-10 like we are used to counting.</p>
<p> Consider this base-10 table with the colun lables at the top and the number of each column below.</p>
<table border="1" cellPadding="0" cellSpacing="0" class="MsoTableGrid">
<tr>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">10000</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">1000</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">100</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">10</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">0</font></p>
</td>
</tr>
<tr>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">9</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">8</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">1</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">5</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">3</font></p>
</td>
</tr>
</table>
<p><font face="Times New Roman">This might look a bit abstract the way it&#8217;s presented. But if you think back to elementary school the columns in a number represent the 10&#8217;s, 100&#8217;s, etc for the number. But the number is 98,153 or (90,000 +8000+ 100+50+3)</font></p>
<p><font face="Times New Roman">Now consider the following binary number, again with the column label at the top and the number of each column at the bottom:</font></p>
<table border="1" cellPadding="0" cellSpacing="0" class="MsoTableGrid">
<tr>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">16</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">8</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">4</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">2</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">1</font></p>
</td>
</tr>
<tr>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">1</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">0</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">1</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">1</font></p>
</td>
<td width="118" vAlign="top">
<p class="MsoNormal"><font size="3" face="Times New Roman">1</font></p>
</td>
</tr>
</table>
<p>This looks a bit more cryptic, but it&#8217;s actually simpler&#8211; we&#8217;ve just been trained to think in decimal. To do the first one we actually had to do multiplication in our head. It wasn&#8217;t (90,000 +8000+ 100+50+3)&#8212; it was actually(9* 10,000) + (8* 1000) + (1 * 100) + (5 * 10) + (3* 1)&#8230; That&#8217;s rather confusing when you spread it out, isn&#8217;t it? but with only 1&#8217;s and 0&#8217;s we don&#8217;t need to do multiplication. (Because 1 * anything is the number, and 0 times anything is 0)</p>
<p>So this is simply 16+4+2+1, or 23! It&#8217;s just a matter of getting to start thinking in powers of 2!</p>
<p>Now, Since I&#8217;ve shared with you previously that a double is larger than an integer, with respect to space, we&#8217;ll continue with that example. If you refer <a target="_blank" href="http://www.developerfusion.co.uk/show/32/">here</a> you&#8217;ll notice that an integer is 2 bytes in Size where a double is 8 bytes in size. What&#8217;s 400% more space amoung friends, right? Quickly <em>doubles</em> can get out of control is you&#8217;re using bunches of them, or placing them in a Database one item at a time&#8230; This is sometimes where developers eat up all our space on the servers, in addition to the <em>backup</em> of the <em>backups</em> in the <em>backups</em> folder that&#8217;s stored in a<em> Do not delete - Save this stuff</em> folder. <img src='http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>The other thing that can be VERY bad! is using a variable type that is to small. Did you notice in the previous link that in Integer represents -32,768 to 32,768? What happens if you add 1 to 32,768? The answer for us is, of course, 32,769! The problem is computers can&#8217;t represent that number in an integer so you get a overflow and the number represented actually looks like -32768 to the computer!</p>
<p> The moral of the story is to always try to use the right type of variable if a variant doesn&#8217;t work for you, and if you plan on using anything other than vbscript, VB, VB.NET, or VBA to create an admin tool&#8211; get accustomed to the different variable types.</p>
<p>Enjoy!</p>
<p><font color="#0000ff"><font color="#0000ff"><font color="#ff0000">Extra credit:</font><font color="#0000ff"> </font></font></font><font color="#000000">10 in base-10 numbering is Ten, 10 in base-2 numbering is 2&#8230; what is 10 in Base-16 numbering and what is it commonly called?</font></p>
]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/binary-numbers/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Reporting CPU usage by saving it to a file with the VBScript filesystem object</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/reporting-cpu-usage-by-saving-it-to-a-file-with-the-vbscript-filesystem-object/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/reporting-cpu-usage-by-saving-it-to-a-file-with-the-vbscript-filesystem-object/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 01:26:34 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
		
		<category><![CDATA[Error control]]></category>

		<category><![CDATA[File System Object]]></category>

		<category><![CDATA[Functions]]></category>

		<category><![CDATA[VBScript]]></category>

		<category><![CDATA[Scripting.FileSystemObject]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/reporting-cpu-usage-by-saving-it-to-a-file-with-the-vbscript-filesystem-object/</guid>
		<description><![CDATA[Last time, in my entry entitled Vbscript to check CPU and Processor performance counter statistics using WMI, I asked you to modify the code I gave to include the access method type in the function. If you haven&#8217;t read teh article, take a second to go back and look it over and digest the code because [...]]]></description>
			<content:encoded><![CDATA[<p>Last time, in my entry entitled <a rel="bookmark" href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/vbscript-to-check-cpu-and-processor-performance-counter-statistics-using-wmi/" title="Permanent Link to Vbscript to check CPU and Processor performance counter statistics using WMI">Vbscript to check CPU and Processor performance counter statistics using WMI</a>, I asked you to modify the code I gave to include the access method type in the function. If you haven&#8217;t read teh article, take a second to go back and look it over and digest the code because this article is identicle to that one, except some added features.</p>
<p>Again I got a rather quick response to the extra credit item that I placed at the end if the article. Basically, you just need to change the code in three places to accomplish this task. We could then use this code in our previous example to create a CSV file for trending and graphing of CPU usage on a server! Here is an example of the code to do this task.</p>
<p>I encourage you to play around with the various methods of file access both with an existing file and a new file that doesn&#8217;t exist.</p>
<p>Below is a working example of the code:</p>
<p><font color="#0000ff"><font color="#0000ff">Option Explicit<br />
On Error Goto 0<br />
Dim strSrv, strQuery,Errors<br />
Dim Counter, Timeframe, Delay</font></font></p>
<p><font color="#0000ff"><font color="#0000ff">Delay = 1000 &#8216;1000 Milliseconds to a second<br />
Timeframe = 300 &#8217;seconds (5 minutes)</font></font></p>
<p><font color="#0000ff"><font color="#0000ff"><br />
strSrv = &#8220;.&#8221;<br />
For Counter = 1 To Timeframe<br />
 Errors = WriteTextFile (&#8221;c:\cpu-usagelog.csv&#8221;, GetFormattedCPU (strSrv), ForAppending)<br />
 WScript.Sleep Delay<br />
Next</font></font><font color="#0000ff"><font color="#0000ff">Const ForReading = 1, ForWriting = 2, ForAppending = 8</font></font><font color="#0000ff"><font color="#0000ff">Function GetFormattedCPU(strSrv)<br />
    Dim objWMIService, Item, Proc, start<br />
   <br />
    start = Now()<br />
  <br />
    strQuery = &#8220;select * from Win32_PerfFormattedData_PerfOS_Processor&#8221;<br />
    Set objWMIService = GetObject(&#8221;winmgmts:\\&#8221; &amp; StrSrv &amp; &#8220;\root\cimv2&#8243;)<br />
    Set Item = objWMIService.ExecQuery(strQuery,,48)<br />
    WScript.Echo strQuery<br />
    For Each Proc In Item<br />
       GetFormattedCPU = GetFormattedCPU &amp; Proc.PercentProcessorTime &amp; &#8220;, &#8220;<br />
       wscript.echo &#8220;Processor &#8221; &amp; Proc.Name &amp; &#8221; = &#8221; &amp; Proc.PercentProcessorTime<br />
    Next<br />
   <br />
    GetFormattedCPU = GetFormattedCPU &amp; start  <br />
 <br />
End Function</font></font><font color="#0000ff"><font color="#0000ff">Function WriteTextFile (OutputFile, Data, AccessType)<br />
    Dim wrtlog, fso<br />
 <br />
    On Error Resume Next<br />
    Set fso = CreateObject(&#8221;Scripting.FileSystemObject&#8221;)<br />
    Set wrtlog = fso.OpenTextFile (OutputFile, AccessType, true)<br />
 If Err.Number &lt;&gt; 0 Then<br />
  Set wrtlog = fso.OpenTextFile (OutputFile, ForWriting, true)<br />
 End If<br />
    wrtlog.WriteLine(Data)<br />
    WriteTextFile = Err.Number &#8216;You can use Err.Description here to debug.<br />
    On Error Goto 0<br />
End Function</font></font><font color="#0000ff"><font color="#0000ff"><font color="#0000ff"><font color="#0000ff"><font color="#0000ff"><font color="#0000ff"><font color="#000000">You now have all the pieces for a fully functional performance logging script, so you&#8217;re well on your way to being able to trobleshoot problems deep in the night without getting up and turning on perfmon. The creates a comma separated value file called cpu-usagelog.csv at the root of the C: drive while the output looks similar to the last time, except it is repeated and I put a time/date stamp in the code by using a new command, <em><strong>now()</strong></em>.</font></font></font></font></font></font></font><font color="#0000ff"><font color="#0000ff"><font color="#000000">Also, pay attention to the error handling around the line that writes the data to the file, you&#8217;ll likely not see an error related to thefile not existing and you using the <em>append</em> access methods, becasue i&#8217;ve checked for it while opening a file.</font></font></font><font color="#0000ff"><font color="#0000ff"><font color="#0000ff"><font color="#0000ff"><font color="#0000ff"><font color="#0000ff"><font color="#000000"> Lastly, notice the for next loop around the function call to call it <em>Timeframe</em> times (Timeframe is multiplied time the sleep <em>Delay</em> to get how long it will capture data). Also notice another new command:</font></font></font></font></font></p>
<p><strong>Wscript.sleep</strong>, which basically pauses the execution for the number of milliseconds you specify in <em>Delay</em>.<font color="#0000ff"><font color="#0000ff"> </font></font></p>
<p><font color="#0000ff"><font color="#0000ff"><font color="#0000ff"><font color="#0000ff"><font color="#000000">Again, 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 for you. From here on out I will make the code available for download from my website’s (<a href="http://www.webstemsadministration.com)/">www.webstemsadministration.com)</a> File Depot under the <font color="#0000ff"><em>ITKE Blog Scripts</em></font> category.</font></font></font><font color="#0000ff"> </font><font color="#0000ff"><font color="#0000ff"><font color="#000000">Enjoy and happy scripting!</font></font></font></font></font></p>
<p><font color="#0000ff"><font color="#0000ff"><font color="#ff0000">Extra credit:</font><font color="#0000ff"> </font><font color="#000000">Try and modify this script to monitor something else that is useful to you. Let us all know how you&#8217;ve used it.</font></font></font></p>
<p></font></font></p>
]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/reporting-cpu-usage-by-saving-it-to-a-file-with-the-vbscript-filesystem-object/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Creating text files using the Scripting.FileSystemObject with VBScript</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/creating-text-files-using-the-scriptingfilesystemobject-with-vbscript/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/creating-text-files-using-the-scriptingfilesystemobject-with-vbscript/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 20:52:08 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
		
		<category><![CDATA[FSO]]></category>

		<category><![CDATA[File System Object]]></category>

		<category><![CDATA[Scripting.FileSystemObject]]></category>

		<category><![CDATA[VBScript]]></category>

		<category><![CDATA[log files]]></category>

		<category><![CDATA[Functions]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/creating-text-files-using-the-scriptingfilesystemobject-with-vbscript/</guid>
		<description><![CDATA[Well, I didn&#8217;t expect the cat to get out of the bag quite so quickly! (Congratulations go out to Stoinov for getting the correct answer I was thinking of so very quickly!) So while he&#8217;s been sleeping during his night, which seems to be my day&#8230; I thought I&#8217;d throw together a quick &#8220;Write a textfile&#8221; script together for [...]]]></description>
			<content:encoded><![CDATA[<p><font color="#0000ff"><font color="#000000">Well, I didn&#8217;t expect the cat to get out of the bag quite so quickly!</font> <font color="#000000">(Congratulations go out to</font> <a href="http://itknowledgeexchange.techtarget.com/profile/Stoinov">Stoinov</a><font color="#000000"> <font color="#000000">for getting the correct answer I was thinking of so very quickly!) So while he&#8217;s been sleeping during his night, which seems to be my day&#8230; I thought I&#8217;d throw together a quick &#8220;Write a textfile&#8221; script together for you all. <em>(A little trivia for you all in the United States, that I found hard to believe when I learned it&#8230; VBScript, and VB for that matter, is in english regardless of where you are in the world. If you&#8217;re on a Japanese system writing VBScript, your using the same language as us folks in the United States. Talk about portable code!)</em></font></font></font></p>
<p>Back to the matter at hand, this script doesn&#8217;t do anything terribly spectacular&#8211; by itself. All it does is opens (or creates) a text file named what you call it where you specify. The heart of the script is the <font color="#0000ff">WriteTextFile () </font>function, which accepts two pieces of data; <strong>a full path to a filename</strong> and <strong>the data you want to write</strong>. That&#8217;s it! But&#8212;- this function will let you write logs, CSV (Comma Separated Value) files or any other form of text file from any type of script for which you choose to use it!</p>
<p>A quick little note on the access method I hard coded into the script. You  will notice three constants used<font color="#0000ff"> ForReading<font color="#000000">,</font> ForWriting<font color="#000000">, and</font> ForAppending </font>these are there so you could change the mode easliy without having to go to the documentation for the <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/314cz14s(VS.85).aspx">OpenTextFile Method</a> of the <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/6kxy1a51(VS.85).aspx">Scripting.FileSystemObject</a> and figure out what numbers to use to change the access method. you simply just need to change the access method from ForReading on the OpenTextFile line of the script to accomplish this task. An excerpt of the Microsoft documentation for the values and descriptions are listed below, for your reference.</p>
<table border="2" width="100%">
<tr>
<th>Constant</th>
<th>Value</th>
<th>Description</th>
</tr>
<tr>
<td>ForReading</td>
<td>1</td>
<td>Open a file for reading only. You can&#8217;t write to this file.</td>
</tr>
<tr>
<td>ForWriting</td>
<td>2</td>
<td>Open a file for writing.</td>
</tr>
<tr>
<td>ForAppending</td>
<td>8</td>
<td>Open a file and write to the end of the file.</td>
</tr>
</table>
<p>Notice it has a ForAppending attribute? If you wanted to &#8230; say log a series of collected values over a number of calls to the script you would have to change the access method to <em>appending</em>, however, keep in mind that ForAppending assunmes the file already exists and you will recieve an error if it doesn&#8217;t.</p>
<p>So, here is the script to write a file&#8230;</p>
<p><font color="#0000ff">Option Explicit<br />
Dim Error</font></p>
<p><font color="#0000ff">Error = WriteTextFile (&#8221;c:\test.txt&#8221;, &#8220;I created a text file with VBScript!&#8221;)<br />
If Error = 0 Then<br />
    WScript.Echo &#8220;File Written Correctly.&#8221;<br />
Else<br />
    WScript.Echo&#8221;Error number &#8221; &amp; Error &amp; &#8221; occured.&#8221;<br />
End If</font></p>
<p><font color="#0000ff">Function WriteTextFile (OutputFile, Data)<br />
    Dim wrtlog, fso<br />
 <br />
    &#8217;these are constants for the OpenTextFile method&#8217;s file access modes<br />
    Const ForReading = 1, ForWriting = 2, ForAppending = 8<br />
  <br />
    On Error Resume Next<br />
    Set fso = CreateObject(&#8221;Scripting.FileSystemObject&#8221;)<br />
    Set wrtlog = fso.OpenTextFile (OutputFile, ForWriting , true)</font></p>
<p><font color="#0000ff">    wrtlog.WriteLine(Data)<br />
    WriteTextFile = Err.Number &#8216;You can use Err.Description here to debug.<br />
End Function</font></p>
<p><font color="#000000">That&#8217;s it. Small, but a <strong><em>VERY</em></strong> powerful tool to add to your toolbelt in scripting.</font></p>
<p><font color="#0000ff"><font color="#0000ff"><font color="#000000">Again, 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 for you. From here on out I will make the code available for download from my website’s (<a href="http://www.webstemsadministration.com)/">www.webstemsadministration.com)</a> File Depot under the <font color="#0000ff"><em>ITKE Blog Scripts</em></font> category.</font></font></font><font color="#0000ff"> </font><font color="#0000ff"><font color="#0000ff"><font color="#000000">Enjoy and happy scripting!</font></font></font></p>
<p><font color="#0000ff"><font color="#0000ff"><font color="#ff0000">Extra credit:</font> <font color="#000000">Can you modify this function to accept a third parameter for the access method?</font></font></font><font color="#0000ff"><font color="#0000ff"><font color="#000000"> I invite you to leave a comment and I’ll let you know if your on the same track as I am. Comments are always welcome!</font></font></font></p>
<p><!--a href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/vbscript-to-check-cpu-and-processor-performance-counter-statistics-using-wmi/trackback/" title="Trackback URL"&amp;gt;Trackback URL</a>&#8211;></p>
]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/creating-text-files-using-the-scriptingfilesystemobject-with-vbscript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Vbscript to check CPU and Processor performance counter statistics using WMI</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/vbscript-to-check-cpu-and-processor-performance-counter-statistics-using-wmi/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/vbscript-to-check-cpu-and-processor-performance-counter-statistics-using-wmi/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 19:11:11 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
		
		<category><![CDATA[Functions]]></category>

		<category><![CDATA[DataCenter]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[VBScript]]></category>

		<category><![CDATA[Remote management]]></category>

		<category><![CDATA[PerfMon]]></category>

		<category><![CDATA[Windows Management Interface]]></category>

		<category><![CDATA[Administration tools]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/vbscript-to-check-cpu-and-processor-performance-counter-statistics-using-wmi/</guid>
		<description><![CDATA[By now, if your reading my blog you&#8217;ve had a chance to play with the script I posted for Using Vbscript to gather server performance counter data with WMI . But I think I might know what you&#8217;re thinking&#8211; &#8220;Hey, that&#8217;s cool&#8230; but I could careless about knowing how much non-paged pool memory there is being used on the [...]]]></description>
			<content:encoded><![CDATA[<p>By now, if your reading my blog you&#8217;ve had a chance to play with the script I posted for <a rel="bookmark" href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-vbscript-to-gather-server-performance-counter-data-with-wmi/" title="Permanent Link to Using Vbscript to gather server performance counter data with WMI">Using Vbscript to gather server performance counter data with WMI</a> . But I think I might know what you&#8217;re thinking&#8211; &#8220;Hey, that&#8217;s cool&#8230; but I could careless about knowing how much non-paged pool memory there is being used on the system! I need to track something useful, like processor utilization or  something else!</p>
<p>Well, you can&#8211; and here you go!  As always the code itself is available on <a href="http://www.webstemsadministration.com)/">my website</a> in the File Depot if you&#8217;d like to avoid copy/paste problems or you don&#8217;t want to type the code yourself.</p>
<p>This script has two functions in it, <font color="#0000ff">GetFormattedCPU() <font color="#000000">and </font>GetRAWCPU() </font><font color="#000000">which both do the same thing, except that one uses a <em>raw</em> performance counter (<em><font color="#000000">Win32_PerfRawData_PerfOS_Processor</font></em>) and the other uses a <em>pre-formatted</em> counter (<font color="#000000"><em>Win32_PerfFormattedData_PerfOS_Processor</em></font>) to get the information from the system. These two counter types, as you will see, give you very different numbers and for the most part you should probably stick with teh pre-formatted counters if at all possible so you don&#8217;t have to do a ton of math to get meaningful data. </font></p>
<p>The functions both return a <em>Comma Delimited</em> string that contains the CPU percantage usage for <strong><em>all</em></strong> processors in the system. Note that, on my dual core system I get 3 numbers&#8211; respective to the return value; Processor 0, Processor 1, and _Total. This should work equally well on Physical SMP systems that are either single or Dual Core, but I suspect on a single core system with more than two processors you will get two numbers that are identicle&#8230; unfortunately, I no longer have a single core system I can test on.</p>
<p><font color="#000000">As always, the code is written in such a way that you can replace the &#8220;.&#8221; with a &#8220;server name&#8221; and it will work remotely on a system&#8211; <em>providing you have administrative rights</em>. Here is the code:</font></p>
<p><font color="#0000ff">Option Explicit<br />
On Error Goto 0<br />
Dim strSrv, strQuery</font><br />
<font color="#0000ff">strSrv = &#8220;.&#8221;</font></p>
<p><font color="#0000ff">WScript.Echo GetFormattedCPU(StrSrv)<br />
WScript.Echo&#8221;______&#8221;<br />
WScript.Echo GetRAWCPU(StrSrv)</font></p>
<p><font color="#0000ff">Function GetFormattedCPU(strSrv)<br />
    Dim objWMIService, Item, Proc<br />
   <br />
    strQuery = &#8220;select * from Win32_PerfFormattedData_PerfOS_Processor&#8221;<br />
    Set objWMIService = GetObject(&#8221;winmgmts:\\&#8221; &amp; StrSrv &amp; &#8220;\root\cimv2&#8243;)<br />
    </font><font color="#0000ff">Set Item = objWMIService.ExecQuery(strQuery,,48)<br />
    WScript.Echo strQuery<br />
    For Each Proc In Item<br />
       GetFormattedCPU = GetFormattedCPU &amp; Proc.PercentProcessorTime &amp; &#8220;, &#8220;<br />
       wscript.echo &#8220;Processor &#8221; &amp; Proc.Name &amp; &#8221; = &#8221; &amp; Proc.PercentProcessorTime<br />
    Next<br />
 <br />
End Function</font></p>
<p><font color="#0000ff">Function GetRAWCPU(StrSrv)<br />
      Dim objWMIService, Item, Proc<br />
    <br />
      strQuery = &#8220;select * from Win32_PerfRawData_PerfOS_Processor&#8221;<br />
   <br />
      Set objWMIService = GetObject(&#8221;winmgmts:\\&#8221; &amp; StrSrv &amp; &#8220;\root\cimv2&#8243;)<br />
      Set Item = objWMIService.ExecQuery(strQuery,,48)<br />
     WScript.Echo strQuery<br />
     For Each Proc In Item<br />
         GetRAWCPU= GetRAWCPU &amp; Proc.PercentProcessorTime &amp; &#8220;,&#8221;<br />
         wscript.echo &#8220;Processor &#8221; &amp; Proc.Name &amp; &#8221; = &#8221; &amp; Proc.PercentProcessorTime<br />
    Next<br />
 <br />
End Function<br />
</font></p>
<p><font color="#0000ff"><font color="#0000ff"><font color="#000000">That&#8217;s it!! As a point of reference, the output of this script looks as follows: </font></font></font></p>
<p><font color="#008000">select * from Win32_PerfFormattedData_PerfOS_Processor<br />
Processor 0 = 0<br />
Processor 1 = 0<br />
Processor _Total = 0<br />
0, 0, 0,<br />
______<br />
select * from Win32_PerfRawData_PerfOS_Processor<br />
Processor 0 = 273670781250<br />
Processor 1 = 275960625000<br />
Processor _Total = 274815703125<br />
273670781250,275960625000,274815703125,</font></p>
<p><font color="#0000ff"><font color="#0000ff"><font color="#000000">Again, 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&#8217;d like to not type or troubleshoot any syntax errors due to the copy and paste problems I&#8217;ve provided the code for download for you. From here on out I will make the code available for download from my website&#8217;s (<a href="http://www.webstemsadministration.com)/">www.webstemsadministration.com)</a> File Depot under the <font color="#0000ff"><em>ITKE Blog Scripts</em></font> category.</font></font></font><font color="#0000ff"> </font><font color="#0000ff"><font color="#0000ff"><font color="#000000">Enjoy and happy scripting!</font></font></font></p>
<p><font color="#0000ff"><font color="#0000ff"><font color="#ff0000">Extra credit:</font> <font color="#000000">Can you guess why I would have <em>messed</em> up your output from the functions in this script by separating the numbers with commas? I invite you to leave a comment and I&#8217;ll let you know if your on the same track as I am. Comments are always welcome!</font></font></font></p>
]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/vbscript-to-check-cpu-and-processor-performance-counter-statistics-using-wmi/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Converting variable types in vbscript from one type to another type</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/converting-variable-types-in-vbscript-from-one-type-another-type/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/converting-variable-types-in-vbscript-from-one-type-another-type/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 01:40:58 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[VBScript]]></category>

		<category><![CDATA[Variable Types]]></category>

		<category><![CDATA[VBScript Statements]]></category>

		<category><![CDATA[Functions]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/converting-variable-types-in-vbscript-from-one-type-another-type/</guid>
		<description><![CDATA[In a previous posting, titled Variable types in VBscript and their upper and lower limits&#8211; just prior to my Rant about CAPTCHA, we discussed the types of variables and why you might want to use them and I showed you a few scenarios where you could get unpredicatable results by not using the proper variable [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous posting, titled <a rel="bookmark" href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/variable-types-in-vbscript-and-their-upper-and-lower-limits/" title="Permanent Link to Variable types in VBscript and their upper and lower limits">Variable types in VBscript and their upper and lower limits</a>&#8211; just prior to <a href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/rant-anyone-else-dislike-those-enter-the-letters-you-see-below-confirmation-pages/">my Rant about CAPTCHA</a>, we discussed the types of variables and why you might want to use them and I showed you a few scenarios where you could get unpredicatable results by not using the proper variable type. If you haven&#8217;t had a chance to read it yet, you might want to go back <a href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/variable-types-in-vbscript-and-their-upper-and-lower-limits/">here</a> before continuing.</p>
<p>In this installment We&#8217;ll discuss the challenge created by using these variable types specifically. Remember, I said that if you use pieces of code or a COM object written in another language it may require a certain type of variable when you call it from your script. <em>(Note, VBScript generally does a good job of converting for you behind the scenes, but it is a best practice to do the conversion on your own first.)</em>  You might be thinking, &#8220;Why not just use a <em>double</em> for everything, that covers a wide enough amount of numbers that I&#8217;ll never be able to use a number that high?&#8221;</p>
<p>Well, the reason is the size of the amount of data it takes because a larger number takes more bits in binary to be represented&#8211; therefor the larger the number (or more correctly the <strong>RANGE</strong> of the variable type) the more space it will take to store it. <em>(A binary lesson may be in order, but not today.)</em>  The last reason is related to the size as well, it takes more processing power to deal with larger numbers because the bus of the CPU is only so wide, and it must sometimes bring the number across the bus in two steps, thus taking more time. Therefore, if you use numbers to big your  scripts can run slower. When I mean slower, I&#8217;m only talking about fractions of a second for the work to be complete, but slow scripts tend to each your life away a millisecond at a time&#8230; Imagine something being a millisecond slower but you have to do it 100,000 times. Now you&#8217;re looking at almost 2 minutes eaten away.</p>
<p>Now, We discussed the types of variables last time, below you will find a table that shows you the function that converts one variable type to another and a link to a useful site showing you how to use the function. Yes, a function. These get fed a number of one type and return a number of another, so you&#8217;ll need to assign the return to another variable when you call them.  <em>(Note: the site referenced uses document.write in it&#8217;s examples, to use the examples in VBScript simply replace document.write with a wscript.echo)</em></p>
<p><strong>VBScript Type Conversion Functions</strong></p>
<table border="1" width="95%" cellPadding="0" cellSpacing="0">
<thead>
<td vAlign="top"><strong>Function</strong></td>
<td vAlign="top"><strong>Description</strong></td>
</tr>
<tr>
<td vAlign="top"><a href="http://www.w3schools.com/vbscript/func_cbool.asp">CBool</a></td>
<td vAlign="top">Converts any nonzero value to True and 0 (zero) to False.</td>
</tr>
<tr>
<td vAlign="top"><a href="http://www.w3schools.com/vbscript/func_cbyte.asp">CByte</a></td>
<td vAlign="top">Converts an expression to a Byte value.</td>
</tr>
<tr>
<td vAlign="top"><a href="http://www.w3schools.com/vbscript/func_ccur.asp">CCur</a></td>
<td vAlign="top">Converts an expression to a Currency value.</td>
</tr>
<tr>
<td vAlign="top"><a href="http://www.w3schools.com/vbscript/func_cdate.asp">CDate</a></td>
<td vAlign="top">Converts an expression to a Date value.</td>
</tr>
<tr>
<td vAlign="top"><a href="http://www.w3schools.com/vbscript/func_cdbl.asp">CDbl</a></td>
<td vAlign="top">Converts an expression to a Double value.</td>
</tr>
<tr>
<td vAlign="top"><a href="http://www.w3schools.com/vbscript/func_cint.asp">CInt</a></td>
<td vAlign="top">Converts an expression to an Integer value. If the fractional part of the expression is .5, CInt will round the value to the nearest even number. For example, 3.5 will be rounded to 4, and 6.5 will be rounded to 6.</td>
</tr>
<tr>
<td vAlign="top"><a href="http://www.w3schools.com/vbscript/func_clng.asp">CLng</a></td>
<td vAlign="top">Converts an expression to a Long value.</td>
</tr>
<tr>
<td vAlign="top"><a href="http://www.w3schools.com/vbscript/func_csng.asp">CSng</a></td>
<td vAlign="top">Converts an expression to a Single value.</td>
</tr>
<tr>
<td vAlign="top"><a href="http://www.w3schools.com/vbscript/func_cstr.asp">CStr</a></td>
<td vAlign="top">Converts an expression to a String value.</td>
</tr>
</table>
<p>This information should be very helpful to you in coverting variables from one type to another in the future. The thing to remember is that you don&#8217;t always need to do this, but if you&#8217;re getting wierd results in your script; check for uninitialized variants, variables of one type (or variant) that are being used with a external piece of code from another language, or for places where a return value is one type and you use it as another.</p>
<p>Enjoy!</p>
<p><font color="#ff0000">Extra credit:</font><font color="#0000ff"> </font><font color="#000000">What happens if you have a variable (of any type) and add enough to it to cause it to go above the maximum value of the variable type? What&#8217;s this generally called?</font></p>
]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/converting-variable-types-in-vbscript-from-one-type-another-type/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
