Last week I wrote a blog showing how to subscribe to and trap AMT WSEvents in PowerShell using the High Level API (HLAPI). That information works great if you want to subscribe to WS-Events, but what about PET events? I will run through a similar demo, only this time we will use PET events:

Again, you will want to load the HLAPI assemblies in PowerShell:

[Reflection.Assembly]::LoadFrom('C:\HLAPI\HLAPI.dll')

[Reflection.Assembly]::LoadFrom('C:\HLAPI\IWSManClient.dll')

And just as we did with the WS-Eventing sample last week, we need to create a connection to our AMT client. Because I am using Digest and Non-TLS mode for this example, I can connect this way:

$auth = [Intel.Manageability.ConnectionInfoEX+AuthMethod]::Digest

$cs = New-ObjectIntel.Manageability.ConnectionInfoEX(“localhost”,”admin”,”P@ssw0rd”,$False,"",$auth,$null,$null, $null)

$amt = [Intel.Manageability.AMTInstanceFactory]::CreateEX($cs)

This is where we start to differ from the WS-Eventing sameple. The PET event will be sent to port 162. Instead of indicating a listener address with a Port Number, we just assign the address (without the HTTP):

$lstn = "192.168.0.5"

Similar to the WS-Eventing example, we also need to choose what Event filter we want to subscribe to. You can find a list of them and what events they cover at this Link

For my simple demo, I just used the “All Events” filter, basically telling AMT to send me an event for any action. Notice the PET filter is defined slightly different than the WS-Eventing example:

$petfilter = New-Object Intel.Manageability.Events.Filter("All_Events")

Next step is to define the senderID type, again I will use FQDN:

$sidtype = [Intel.Manageability.Events.SenderIDType]::FQDN

Now we can pull it all together into a “subscription”:

$sub = New-Object Intel.Manageability.Events.PETSubscription($lstn,$petfilter,$sidtype)

And finally we can use our AMT connection to subscribe, making sure we select PETEvents this time.

$amt.Events.PETEvents.Subscribe($sub)

Now that we have our subscription, we can move over to our server and create a listener. We start out again by loading the HLAPI:

[Reflection.Assembly]::LoadFrom('C:\HLAPI\HLAPI.dll')

[Reflection.Assembly]::LoadFrom('C:\HLAPI\IWSManClient.dll')

We can now create our listener:

$listener = New-Object HLAPI.Services.PETEventListener

Now we just need to define what happens when we receive a new message. For this example we will just capture the FQDN of the system sending the message:

Register-ObjectEvent $listener OnNewEventArrived -SourceIdentifier $listener.OnNewEventArrived  -Action {write-host ""; write-host "FQDN: "$Event.SourceEventArgs.Sender ;}

Now all that is left is to start the listener:

$listener.StartListening()

Now we are ready to generate another event from my AMT client.

I will push the "Get Technical Help" button again:

pet.PNG

As you can see the listener received the alert and displayed the FQDN of the AMT client!

 

For more information regarding the High Level API and Events check out this Link.