<?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>Wayne Zimmerman&#039;s Blog &#187; Report</title>
	<atom:link href="http://www.waynezim.com/tag/report/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.waynezim.com</link>
	<description>My World of Tech, Life and Anything Else</description>
	<lastBuildDate>Fri, 10 Feb 2012 00:13:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Report Workstation Uptime in a CSV using Active Directory and VBS</title>
		<link>http://www.waynezim.com/2009/07/report-workstation-uptime-in-a-csv-using-active-directory-and-vbs/</link>
		<comments>http://www.waynezim.com/2009/07/report-workstation-uptime-in-a-csv-using-active-directory-and-vbs/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 19:56:09 +0000</pubDate>
		<dc:creator>Wayne Zimmerman</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Computer]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[Domain]]></category>
		<category><![CDATA[Report]]></category>
		<category><![CDATA[Uptime]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[VBscript]]></category>

		<guid isPermaLink="false">http://www.waynezim.com/?p=437</guid>
		<description><![CDATA[Have you ever been left wondering which computers on your domain have been neglected by their user and not restarted in forever? This is a question that come up in my office every once and a while. One of the easiest ways to solve this problem is to ask WMI for when the computer was [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever been left wondering which computers on your domain have been neglected by their user and not restarted in forever? This is a question that come up in my office every once and a while. One of the easiest ways to solve this problem is to ask WMI for when the computer was last restarted and subtract it from the current time. Also, while asking WMI questions you might as well ask which user is currently logged on the PC that way you know who to blame. This is exactly what the following script does for your domain. It grabs the list of workstations from the domain then queries WMI for the last time the computer is restarted and does some conversion and math and makes you an nice CSV that you can play with. </p>
<p><b>Script Configuration</b><br />
Before running this script there is some minor configuration that must be done so it can communicate with your Active Directory setup.
<ol>
<li>Find <code>objConnection.Open "Active Directory Server"</code> change <em>Active Directory Server</em> to the name of your Domain Controller</li>
<li>Find <code>objCommand.CommandText = _<br />
    "Select Name, Location from 'LDAP://OU=Workstations,DC=west,DC=domain,DC=edu' " _<br />
        &#038; "Where objectClass='computer'"</code> change <em>subdomain</em>, <em>domain</em>, and <em>suffix</em> to the name of your domain i.e. west domain edu (respectively)</li>
<li>Find <code>GetUptime objRecordSet.Fields("Name").Value, "C:\uptime.csv"</code> and change <em>C:\uptime.csv</em> to the location where you want the file saved. Be sure to save it with the extension CSV
</ol>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.waynezim.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=437&amp;download=GetUptime.vbs">GetUptime.vbs</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4372"><td class="code" id="p437code2"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Const</span> ADS_SCOPE_SUBTREE = 2
&nbsp;
<span style="color: #000080;">Set</span> objConnection = CreateObject(<span style="color: #800000;">&quot;ADODB.Connection&quot;</span>)
<span style="color: #000080;">Set</span> objCommand =   CreateObject(<span style="color: #800000;">&quot;ADODB.Command&quot;</span>)
objConnection.Provider = <span style="color: #800000;">&quot;ADsDSOObject&quot;</span>
objConnection.<span style="color: #000080;">Open</span> <span style="color: #800000;">&quot;Active Directory Server&quot;</span> 
&nbsp;
<span style="color: #000080;">Set</span> objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
    <span style="color: #800000;">&quot;Select Name, Location from 'OU=Workstations,DC=west,DC=domain,DC=edu' &quot;</span> _
        &amp; <span style="color: #800000;">&quot;Where objectClass='computer'&quot;</span>  
objCommand.Properties(<span style="color: #800000;">&quot;Page Size&quot;</span>) = 1000
objCommand.Properties(<span style="color: #800000;">&quot;Searchscope&quot;</span>) = ADS_SCOPE_SUBTREE 
<span style="color: #000080;">Set</span> objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
&nbsp;
<span style="color: #000080;">Do</span> <span style="color: #000080;">Until</span> objRecordSet.EOF
	GetUptime objRecordSet.Fields(<span style="color: #800000;">&quot;Name&quot;</span>).Value, <span style="color: #800000;">&quot;C:\uptime.csv&quot;</span>
    objRecordSet.MoveNext
<span style="color: #000080;">Loop</span>
&nbsp;
<span style="color: #000080;">Sub</span> GetUptime(strComputer, strFilename)
	<span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">Resume</span> <span style="color: #000080;">Next</span>
	<span style="color: #000080;">Set</span> StdOut = WScript.StdOut
&nbsp;
	<span style="color: #000080;">Set</span> objFSO = CreateObject(<span style="color: #800000;">&quot;scripting.filesystemobject&quot;</span>)
	<span style="color: #000080;">Set</span> logStream = objFSO.opentextfile(strFilename, 8, <span style="color: #000080;">True</span>)
&nbsp;
	<span style="color: #000080;">Set</span> oReg=GetObject(<span style="color: #800000;">&quot;winmgmts:{impersonationLevel=impersonate}!\\&quot;</span> &amp; strComputer &amp; <span style="color: #800000;">&quot;\root\default:StdRegProv&quot;</span>)
	<span style="color: #000080;">If</span> Err.Number <span style="color: #000080;">Then</span>
	      logStream.writeline(strComputer &amp; <span style="color: #800000;">&quot;,Offline&quot;</span>)
	      Err.Clear
	<span style="color: #000080;">Else</span>
		<span style="color: #000080;">Set</span> objWMIService = GetObject _
			(<span style="color: #800000;">&quot;winmgmts:\\&quot;</span> &amp; strComputer &amp; <span style="color: #800000;">&quot;\root\cimv2&quot;</span>)
		<span style="color: #000080;">Set</span> colOperatingSystems = objWMIService.ExecQuery _
			(<span style="color: #800000;">&quot;Select * from Win32_OperatingSystem&quot;</span>)
		<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> objOS <span style="color: #000080;">in</span> colOperatingSystems
			dtmBootup = objOS.LastBootUpTime
			dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
			dtmSystemUptime = DateDiff(<span style="color: #800000;">&quot;h&quot;</span>, dtmLastBootUpTime, Now()) 
		<span style="color: #000080;">Next</span>
		<span style="color: #000080;">Set</span> objWMIService = GetObject _
			(<span style="color: #800000;">&quot;winmgmts:\\&quot;</span> &amp; strComputer &amp; <span style="color: #800000;">&quot;\root\cimv2&quot;</span>)
		<span style="color: #000080;">Set</span> colComputerSys = objWMIService.ExecQuery _
			(<span style="color: #800000;">&quot;Select UserName from Win32_ComputerSystem&quot;</span>)
		<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> objCS <span style="color: #000080;">in</span> colComputerSys
			username = objCS.UserName
			logStream.writeline(strComputer &amp; <span style="color: #800000;">&quot;,Online,&quot;</span> &amp; dtmSystemUptime &amp; <span style="color: #800000;">&quot;,&quot;</span> &amp; dtmLastBootupTime &amp; <span style="color: #800000;">&quot;,&quot;</span> &amp; username) 
		<span style="color: #000080;">Next</span>
&nbsp;
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
	logStream.<span style="color: #000080;">Close</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
<span style="color: #000080;">Function</span> WMIDateStringToDate(dtmBootup)
    WMIDateStringToDate = <span style="color: #000080;">CDate</span>(Mid(dtmBootup, 5, 2) &amp; <span style="color: #800000;">&quot;/&quot;</span> &amp; _
         Mid(dtmBootup, 7, 2) &amp; <span style="color: #800000;">&quot;/&quot;</span> &amp; Left(dtmBootup, 4) _
         &amp; <span style="color: #800000;">&quot; &quot;</span> &amp; Mid (dtmBootup, 9, 2) &amp; <span style="color: #800000;">&quot;:&quot;</span> &amp; _
         Mid(dtmBootup, 11, 2) &amp; <span style="color: #800000;">&quot;:&quot;</span> &amp; Mid(dtmBootup, _
         13, 2))
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.waynezim.com/2009/07/report-workstation-uptime-in-a-csv-using-active-directory-and-vbs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Weekly Terminal Services Connection Report using VBS</title>
		<link>http://www.waynezim.com/2009/06/weekly-terminal-services-connection-report-using-vbs/</link>
		<comments>http://www.waynezim.com/2009/06/weekly-terminal-services-connection-report-using-vbs/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 15:47:14 +0000</pubDate>
		<dc:creator>Wayne Zimmerman</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[Event Log]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Remote Administration]]></category>
		<category><![CDATA[Remote Desktop Connection]]></category>
		<category><![CDATA[Report]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SMTP]]></category>
		<category><![CDATA[Terminal Services]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[VBscript]]></category>

		<guid isPermaLink="false">http://www.waynezim.com/?p=314</guid>
		<description><![CDATA[A few weeks ago we had some state auditors come by and mention that we should review our logs for any sort of outside / vendor access. I knew that going to each server and reviewing the logs manually would be very time consuming and not really provide solid documentation that it was done. I [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago we had some state auditors come by and mention that we should review our logs for any sort of outside / vendor access. I knew that going to each server and reviewing the logs manually would be very time consuming and not really provide solid documentation that it was done. I decided that the only way to solve this problem was with a report of some nature. I fired up my trusty Crystal Reports and started to view the logs using that, once I got in to more I realized that when I added the description field of the event log it always crashed Crystal Reports. This left me going to plan B which is writing the reports from scratch using Visual Basic Scripting language.</p>
<p>I already knew that you can use VBS to connect to WMI (Windows Management Interface) and view different parts of the system including the event log, so I spent the morning writing the report and parsing it down to the detail that I really needed. Then I decided to take it to the next level by adding in recursion for multiple servers and also set it up to send an HTML email so it is easy to review every week. Why every week you may ask, well in looking at my event log on my domain server I noticed that I start losing Security events at about 10-14 days out since it is authorizing so much, and a weekly task is a very manageable one.</p>
<p><b>Script Configuration</b></p>
<ol>
<li>Configure the servers that this script will report on. Modify the <em>Servers</em> array for each server that needs to be checked. (Note: all servers need the same login credentials for the script to work)</li>
<li>Find the <em>objMessage.From</em> field and update it with who the email is coming from</li>
<li>Find the <em>objMessage.To</em> Field and update with the email address of the person who will be receiving the report, if you have multiple addresses to send to separate them with a semi-colon (;)</li>
<li>Find the <em>(&#8220;http://schemas.microsoft.com/cdo/configuration/smtpserver&#8221;) = &#8220;smtp-relay.waynezim.com&#8221;</em> and update this with your SMTP server, if your server requires authentication you will need to modify this script to include that, a simple Google search should show you what needs to be changed.</li>
<li>This script should be setup to be a scheduled task on one of your servers, the credentials used in setting up the job will be used to connect to the other servers, this account needs to exist on all servers to view the Security Event Log and make the report.</li>
<li>To setup a scheduled task, go to your <em>Control Panel</em>, open <em>Scheduled Tasks</em>, right click <em>New > Scheduled Task</em>, name it, then right click and modify the <em>Properties</em>, <em>Browse</em> to where the script is saved, set the <em>Run as</em> at the bottom for the user that exists on all Servers and set the password. Then go to the <em>Schedule</em> tab and set it to <em>Weekly</em> and change it to run when you want it to.</li>
</ol>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.waynezim.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=314&amp;download=RemoteConnectionsReport.vbs">RemoteConnectionsReport.vbs</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3144"><td class="code" id="p314code4"><pre class="vbs" style="font-family:monospace;">Dim objWMI, objEvent ' Objects
Dim strComputer ' Strings
Dim intEvent, intNumberID, intRecordNum, colLoggedEvents
'--------------------------------------------
' Server List to Parse Logs
Dim Servers(5)
Servers(0) = &quot;server1&quot;
Servers(1) = &quot;server2&quot;
Servers(2) = &quot;server3&quot;
Servers(3) = &quot;server4&quot;
Servers(4) = &quot;server5&quot;
Servers(5) = &quot;server6&quot;
'--------------------------------------------
' Email Body Heading
HTMLMsg = &quot;&lt;html&gt;&lt;body&gt;&lt;h3&gt;Remote Desktop Connections from &quot; &amp; cDate(Now() - 7) &amp; &quot; to &quot; &amp; cDate(Now()) &amp; &quot;&lt;/h3&gt;&quot;
HTMLMsg = HTMLMsg &amp; &quot;&lt;table border=1&gt;&lt;tr&gt;&lt;td&gt;&lt;b&gt;Computer Name&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Logon Type&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Remote IP&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Date / Time&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;User&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&quot;
'--------------------------------------------
' Next section creates the file to store Events
' Then creates WMI connector to the Logs
&nbsp;
'Range Variable - Out of Loop for Common Report Time
WeekAgo = cDate(Now() - 7)
&nbsp;
'Start Each Computer Loop
For Each strComputer in Servers
' --------------------------------------------
' Set your variables for Events Loop
intEvent = 1
intRecordNum = 1
&nbsp;
Set objWMI = GetObject(&quot;winmgmts:&quot; _
&amp; &quot;{impersonationLevel=impersonate}!\\&quot; _
&amp; strComputer &amp; &quot;\root\cimv2&quot;)
Set colLoggedEvents = objWMI.ExecQuery _
(&quot;Select * from Win32_NTLogEvent Where Logfile = 'Security' AND EventCode = 528 AND TimeWritten &gt; '&quot; &amp; WeekAgo &amp; &quot;'&quot;)
' -----------------------------------------
' Next section loops through ID properties
intEvent = 1
	For Each objEvent in colLoggedEvents
&nbsp;
	HTMLMsg = HTMLMsg &amp; &quot;&lt;tr&gt;&lt;td&gt;&quot; &amp; objEvent.ComputerName &amp; &quot;&lt;/td&gt;&quot;
	LogonType = RTrim(Mid(objEvent.Message,InStr(objEvent.Message,&quot;Logon Type:&quot;)+12,2))
	If LogonType = 2 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Interactive&lt;/td&gt;&quot; End if
	If LogonType = 3 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Network&lt;/td&gt;&quot; End if
	If LogonType = 4 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Batch&lt;/td&gt;&quot; End if
	If LogonType = 5 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Service&lt;/td&gt;&quot; End if
	If LogonType = 7 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Unlock&lt;/td&gt;&quot; End if
	If LogonType = 8 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Network using Clear Text&lt;/td&gt;&quot; End if
	If LogonType = 9 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;New Credentials&lt;/td&gt;&quot; End if
	If LogonType = 10 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Remote Interactive&lt;/td&gt;&quot; End if
	If LogonType = 11 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Cached Interaction&lt;/td&gt;&quot; End if
&nbsp;
	IPlen = InStr(InStr(objEvent.Message,&quot;Source Network Address:&quot;)+24,objEvent.Message,&quot;	&quot;) - InStr(objEvent.Message,&quot;Source Network Address:&quot;) - 28
	RemoteAddress = RTrim(Mid(objEvent.Message,InStr(objEvent.Message,&quot;Source Network Address:&quot;)+24,IPlen))
	HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;&quot; &amp; RemoteAddress &amp; &quot;&lt;/td&gt;&quot;
	EventTime = Mid(objEvent.TimeWritten, 5, 2) &amp; &quot;/&quot; &amp; Mid(objEvent.TimeWritten, 7, 2) &amp; &quot;/&quot; &amp; Mid(objEvent.TimeWritten, 1, 4) &amp; &quot; &quot; &amp; Mid(objEvent.TimeWritten, 9, 2) &amp; &quot;:&quot; &amp; Mid(objEvent.TimeWritten, 11, 2) &amp; &quot;.&quot; &amp; Mid(objEvent.TimeWritten, 13, 2)
	HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;&quot; &amp; EventTime &amp; &quot;&lt;/td&gt;&quot;
	HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;&quot; &amp; objEvent.User &amp; &quot;&lt;/td&gt;&lt;/tr&gt;&quot;
	intRecordNum = intRecordNum +1
	IntEvent = intEvent +1
&nbsp;
	Next
Next
&nbsp;
Set objMessage = CreateObject(&quot;CDO.Message&quot;)
objMessage.Subject = &quot;Remote Connections Report: &quot; &amp; cDate(Now())
objMessage.From = &quot;root@waynezim.com&quot;
objMessage.To = &quot;waynezim@waynezim.com&quot;
objMessage.HTMLBody = HTMLMsg
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
(&quot;http://schemas.microsoft.com/cdo/configuration/sendusing&quot;) = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserver&quot;) = &quot;smtp-relay.waynezim.com&quot;
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserverport&quot;) = 25
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
&nbsp;
objMessage.Send
WScript.Quit</pre></td></tr></table></div>

<p><b>Report Preview</b><br />
If you need help decoding what Logon Type really means check out this <a href="http://www.windowsecurity.com/articles/Logon-Types.html">great article. </a></p>
<table border=0>
<tr>
<td>
<a href="http://www.waynezim.com/wp-content/uploads/2009/06/remote-connection-report-preview.png"><img src="http://www.waynezim.com/wp-content/uploads/2009/06/remote-connection-report-preview.png" alt="remote-connection-report-preview" title="remote-connection-report-preview" width="675" height="253" class="alignleft size-full wp-image-324" /></a></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.waynezim.com/2009/06/weekly-terminal-services-connection-report-using-vbs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

