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
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
- Oisin