Skip to content

Instantly share code, notes, and snippets.

@aetos382
Last active July 28, 2016 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aetos382/9d87b64111b94be8ff15e17b8f7e15b7 to your computer and use it in GitHub Desktop.
Save aetos382/9d87b64111b94be8ff15e17b8f7e15b7 to your computer and use it in GitHub Desktop.
# This query is valid. __InstanceCreationEvent class has TargetInstance property.
$query = @'
SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process' AND TargetInstance.Name = 'cmd.exe'
'@
$evt = Register-CimIndicationEvent -Query $query -SourceIdentifier 'TestEvent' -Action {
$EventArgs | Get-Member -Force | Out-Default
$EventArgs | Format-List * | Out-Default
$e = $EventArgs.NewEvent
$e | Get-Member -Force | Out-Default
$e | Format-List * | Out-Default
$instance = $e.TargetInstance
$instance | Get-Member -Force | Out-Default
$instance | Format-List * | Out-Default
}
$evt
# Unregister-Event -SourceIdentifier 'TestEvent'
# This query is invalid. Why? CIM_InstCreation has SourceInstance property.
$query = @'
SELECT * FROM CIM_InstCreation WITHIN 1 WHERE SourceInstance ISA 'Win32_Process' AND SourceInstance.Name = 'cmd.exe'
'@
$evt = Register-CimIndicationEvent -Query $query -SourceIdentifier 'TestEvent' -Action {
$EventArgs | Get-Member -Force | Out-Default
$EventArgs | Format-List * | Out-Default
$e = $EventArgs.NewEvent
$e | Get-Member -Force | Out-Default
$e | Format-List * | Out-Default
$instance = $e.SourceInstance
$instance | Get-Member -Force | Out-Default
$instance | Format-List * | Out-Default
}
$evt
# Unregister-Event -SourceIdentifier 'TestEvent'
# This query is valid. Why? CIM_InstCreation class doesn't have TargetInstance property.
$query = @'
SELECT * FROM CIM_InstCreation WITHIN 1 WHERE SourceInstance ISA 'Win32_Process' AND TargetInstance.Name = 'cmd.exe'
'@
$evt = Register-CimIndicationEvent -Query $query -SourceIdentifier 'TestEvent' -Action {
$EventArgs | Get-Member -Force | Out-Default
$EventArgs | Format-List * | Out-Default
$e = $EventArgs.NewEvent
$e | Get-Member -Force | Out-Default
$e | Format-List * | Out-Default
$instance = $e.SourceInstance
$instance | Get-Member -Force | Out-Default
$instance | Format-List * | Out-Default
}
$evt
# Unregister-Event -SourceIdentifier 'TestEvent'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment