<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Working with WMI Events (2)</title><link>http://blogs.msdn.com/powershell/archive/2007/07/16/working-with-wmi-events-2.aspx</link><description>This post builds on Jeffrey's post on wmi events - http://blogs.msdn.com/powershell/archive/2007/01/28/working-with-wmi-events.aspx Powershell V1 does not give a cmdlet to support WMI events, I have written a simple powershell script to help users who</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Working with WMI Events (2)</title><link>http://blogs.msdn.com/powershell/archive/2007/07/16/working-with-wmi-events-2.aspx#3897790</link><pubDate>Mon, 16 Jul 2007 19:28:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3897790</guid><dc:creator>Oisin Grehan</dc:creator><description>&lt;p&gt;The only caveat here is WaitForNextEvent blocks all keyboard input you receieve an event, this includes Ctrl+C. So if you screw up, you have to kill your powershell session. &lt;/p&gt;
&lt;p&gt;If you're more familiar with traditional .net events, the Wmi Watcher class exposes a EventArrived event. Powershell v1 doesn't have any solid support for handling sync or async events, so enter my shameless plug for my free, open-source eventing library: &lt;a rel="nofollow" target="_new" href="http://www.codeplex.com/pseventing"&gt;http://www.codeplex.com/pseventing&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This library allows you to subscribe to standard events and collect them in the background while you get on with scripting:&lt;/p&gt;
&lt;p&gt;1 PS&amp;gt; $watch = gwe -Class &amp;quot;Win32_ProcessStartTrace&amp;quot;&lt;/p&gt;
&lt;p&gt;2 PS&amp;gt; Connect-EventListener watch eventarrived,disposed -Verbose&lt;/p&gt;
&lt;p&gt;VERBOSE: Target is a ManagementEventWatcher&lt;/p&gt;
&lt;p&gt;VERBOSE: Now listening for 'eventarrived' events from $watch&lt;/p&gt;
&lt;p&gt;VERBOSE: Target is a ManagementEventWatcher&lt;/p&gt;
&lt;p&gt;VERBOSE: Now listening for 'disposed' events from $watch&lt;/p&gt;
&lt;p&gt;3 PS&amp;gt; $watch.Start()&lt;/p&gt;
&lt;p&gt;Now, if you really want to block and wait, use:&lt;/p&gt;
&lt;p&gt;4 PS&amp;gt; get-event -wait&lt;/p&gt;
&lt;p&gt;except this time you can break out with ctrl+c at any time.&lt;/p&gt;
&lt;p&gt;alternatively, continue scripting away and check for events with get-event:&lt;/p&gt;
&lt;p&gt;4 PS&amp;gt; $events = get-event&lt;/p&gt;
&lt;p&gt;5 PS&amp;gt; $events | ft -auto&lt;/p&gt;
&lt;p&gt;Occurred &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Source &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Name &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Args&lt;/p&gt;
&lt;p&gt;-------- &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;------ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;---- &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ----&lt;/p&gt;
&lt;p&gt;07/16/2007 12:24 PM System.Management.Automation.PSVariable EventArrived System.Management.EventArrivedEventArgs&lt;/p&gt;
&lt;p&gt;Btw, the Source property is a reference to the $watch variable. I believe powershell v2 has some kind of event handling, and I'd be interested to hear more about it from you guys. You've been suspiciously quiet about it all ;-)&lt;/p&gt;
&lt;p&gt;Thanks guys for a great product!&lt;/p&gt;
&lt;p&gt;- Oisin / x0n&lt;/p&gt;</description></item><item><title>re: Working with WMI Events (2)</title><link>http://blogs.msdn.com/powershell/archive/2007/07/16/working-with-wmi-events-2.aspx#3907908</link><pubDate>Tue, 17 Jul 2007 09:03:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3907908</guid><dc:creator>kmathur</dc:creator><description>&lt;p&gt;Nice! A plugin to support async eventing for powershell. Interesting project. &lt;/p&gt;</description></item><item><title>Working with WMI Events in powershell</title><link>http://blogs.msdn.com/powershell/archive/2007/07/16/working-with-wmi-events-2.aspx#3908758</link><pubDate>Tue, 17 Jul 2007 10:13:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3908758</guid><dc:creator>kapslock</dc:creator><description>&lt;p&gt;I posted the following on Powershell team's blog - Powershell V1 does not give a cmdlet to support WMI&lt;/p&gt;
</description></item><item><title>Working with WMI Events in powershell</title><link>http://blogs.msdn.com/powershell/archive/2007/07/16/working-with-wmi-events-2.aspx#3908812</link><pubDate>Tue, 17 Jul 2007 10:19:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3908812</guid><dc:creator>Noticias externas</dc:creator><description>&lt;p&gt;I posted the following on Powershell team&amp;amp;#39;s blog - Powershell V1 does not give a cmdlet to support&lt;/p&gt;
</description></item><item><title>re: Working with WMI Events (2)</title><link>http://blogs.msdn.com/powershell/archive/2007/07/16/working-with-wmi-events-2.aspx#4011581</link><pubDate>Mon, 23 Jul 2007 19:36:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4011581</guid><dc:creator>Wolfmandragon</dc:creator><description>&lt;p&gt;When I run this script I get an error message of for the line of &lt;/p&gt;
&lt;p&gt;$result = $watch.WaitForNextEvent()&lt;/p&gt;
&lt;p&gt;exception calling &amp;quot;WaitForNextEvent()&amp;quot; with &amp;quot;0&amp;quot; argument(s): &amp;quot;Unparsable query. &amp;quot;&lt;/p&gt;
&lt;p&gt;if I take out &amp;quot;()&amp;quot; then I get no error message but there is also no event logs raised. Could someone explain this please.&lt;/p&gt;</description></item></channel></rss>