<?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>PowerShell Station &#187; WMI</title>
	<atom:link href="http://powershellstation.com/category/wmi/feed/" rel="self" type="application/rss+xml" />
	<link>http://powershellstation.com</link>
	<description>Mike&#039;s PowerShell Musings</description>
	<lastBuildDate>Thu, 05 Apr 2012 03:05:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Get-EventLog and Get-WMIObject</title>
		<link>http://powershellstation.com/2009/12/16/get-eventlog-and-get-wmiobject/</link>
		<comments>http://powershellstation.com/2009/12/16/get-eventlog-and-get-wmiobject/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 05:51:39 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://powershellstation.com/?p=209</guid>
		<description><![CDATA[Recently, we had an occasion to write a process to read event logs on several sql servers to try to determine login times for different sql and Windows logins.  Since we have begun using PowerShell v2.0, and since get-eventlog now has a -computername parameter, it seemed like an obvious solution. The event message we were [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, we had an occasion to write a process to read event logs on several sql servers to try to determine login times for different sql and Windows logins.  Since we have begun using PowerShell v2.0, and since get-eventlog now has a -computername parameter, it seemed like an obvious solution.</p>
<p>The event message we were interested in looked something like &#8220;Login succeeeded for uesr &#8216;UserName&#8217; &#8230;.&#8221;.  The code we were trying to use was:</p>
<pre class="brush: powershell">
get-eventlog -computername $servername -logname Application -message "Login succeeded for user*" -after ((get-date).AddDays(-1))
</pre>
<p>I expected that, given a date parameter and a leading string to match wouldn&#8217;t be too bad, but this ended up taking several minutes per server.  As there are over a hundred servers to scan, that didn&#8217;t work well for us.</p>
<p>We ended up falling back to get-wmiobject.</p>
<pre class="brush: powershell">
$BeginDate=[System.Management.ManagementDateTimeConverter]::ToDMTFDateTime((get-date).AddDays(-1))
get-wmiobject -class win32_ntlogevent -computerName $servername -filter "(EventCode=18453)  and (LogFile='Application') and (TimeGenerated &gt;'$BeginDate')"
</pre>
<p>Cons:</p>
<ul>
<li><span style="color: #000000;">We have to encode the date parameter (instead of using a nice datetime parameter like get-eventlog has)</span></li>
<li><span style="color: #000000;">We have to write a WQL where-clause to match the parameters<br />
</span></li>
</ul>
<p><span style="color: #000000;">Pros:</span></p>
<ul>
<li><span style="color: #000000;">We get to use the event code (rather than a string match)</span></li>
<li><span style="color: #000000;">The code is orders of magnitude faster (39 servers in 13 minutes as a test case)<br />
</span></li>
</ul>
<p><span style="color: #000000;"> I think that you might have a positive experience using get-eventlog if you need to scan a range of time (for instance if you&#8217;re reporting on what happened on the server), but if you need to look for a specific event (or set of events) you&#8217;re probably going to want to use get-wmiobject.</span></p>
<p><span style="color: #000000;">-Mike<br />
</span></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpowershellstation.com%2F2009%2F12%2F16%2Fget-eventlog-and-get-wmiobject%2F&amp;title=Get-EventLog%20and%20Get-WMIObject" id="wpa2a_2"><img src="http://powershellstation.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://powershellstation.com/2009/12/16/get-eventlog-and-get-wmiobject/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  powershellstation.com/category/wmi/feed/ ) in 0.22486 seconds, on May 20th, 2012 at 1:27 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on May 21st, 2012 at 1:27 am UTC -->
