Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Register-WMIEvent cmdlet

7 views
Skip to first unread message

Simon

unread,
Sep 10, 2008, 9:45:22 AM9/10/08
to
Hi,

I am wondering if anybody has used this cmdlet much? I have only found
one example of its use, and there is no built in help (get-help) for
it. My main question is how to pass the event into the action block
parameter? For example, here is the command I am running:

Register-WmiEvent -ComputerName $server -query "Select * from
__InstanceCreationEvent within 3 where TargetInstance ISA
'Msvm_ComputerSystem'" -SourceIdentifier "VMCreated" -action {Write-
Host "A VM has been created."} -Namespace 'root\virtualization'

What I would like to be able to do is to reference the even in my
action block, so that I could print out (initially) some information
about it, like what the VM name is for example. I have tried using
the $_ variable, but this doesn't seem to work for me. Does anybody
have any advice/ideas?

Thanks,

Simon

Oisin (x0n) Grehan [MVP]

unread,
Sep 10, 2008, 8:27:42 PM9/10/08
to
Hi Simon,

If you change your action scriptblock to be:

{ write-host $args }

you will see exactly what is being passed into the handler.

For another example, using register-objectevent and event forwarding,
check out

http://www.nivot.org/2008/08/16/AutoMountunmountNewPSDrivesForRemovableDrivesAndNetworkSharesInPowerShellV2.aspx

- Oisin

0 new messages