# System Events

![System Events in the Admin Console](https://620394196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1JcgdTkn7CUOMdfsVjOO%2Fuploads%2F2YGTXSbSZbeZEq1b42rC%2Fimage.png?alt=media\&token=33319f6c-5266-4262-baf5-ee359f38b914)

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"
```
