Online Help
PowerShell Examples for Custom Audit Fields
This page collects ready-to-use PowerShell samples for Windows custom audit fields. Copy a sample into the Script box when Filling method is set to Script, then replace the placeholder values with data from your environment.
Note: Each script should return a value that matches the field's
Type. UseTablefor multi-value output andLogicalfor true/false checks.
Before you start
- Create the custom audit field.
- Set Device type to the Windows device type you want to audit.
- Choose a
Typethat matches the script output. - Set Filling method to
Script. - Paste one of the samples below into the Script box and test it in a controlled environment.
PowerShell script samples
Collecting system information
Use this pattern when you want to collect a set of values from Windows hardware or system classes. In the example below, AlloyScan can store the returned property list in a Table field.
$Result = Get-WmiObject Win32_PortConnector | Select-Object InternalReferenceDesignator
This sample:
- queries the
Win32_PortConnectorWMI class; - keeps only the
InternalReferenceDesignatorproperty; - returns a collection of values, so
Tableis the most suitable field type.
Capturing Registry keys
Use this pattern when you need a logical yes/no result from the registry.
[bool] (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\SrpV2' -Name 'EnforcementMode' -ErrorAction SilentlyContinue)
This sample:
- checks whether AppLocker Enforcement Mode is enabled;
- returns
$trueor$false; - fits a
Logicalfield type.
Checking file presence
Use this pattern when the script should report whether a file exists on the system.
[bool] (Test-Path -Path 'C:\ProgramData\MyApp\license.lic')
This sample:
- verifies whether the file is present;
- returns
$trueor$false; - also fits a
Logicalfield type.