# System Events

![System Events in the Admin Console](/files/ByU2xzYz3jvdnOWtqmet)

System events subscribe to WMI events within Windows and run scripts. You can then take action by running scripts.&#x20;

## Defining a System Event

To define a system event, you can use the `New-PSUSystemEvent` cmdlet within the `systemEvents.ps1` file. The following example triggers the `systemEvent.ps1` script when a `pwsh.exe` process is started.

```powershell
New-PSUSystemEvent -Script "systemEvent.ps1" -Environment "Default" -Credential "Default" -Type "Create" -Condition "TargetInstance isa `"Win32_Process`" and TargetInstance.Name = `"pwsh.exe`"" -Name "PowerShell Started"
```

## Accessing Event Data

When a script is executed, you will receive a `$TargetInstance` parameter. This contains the WMI object that caused the event to trigger.&#x20;

```powershell
param($TargetInstance)

New-BurntToastNotification -Text "PowerShell Started! $TargetInstance"
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.powershelluniversal.com/v4-beta/automation/system-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
