Process logging in PowerShell target connectors
In PowerShell target connectors (both v1 and v2), Process logs is done through native PowerShell cmdlets; see Logging cmdlets.
Alternatively, custom messages can be written to the Audit logs; see Manually writing messages into audit logs.
Logging errors
Use Write-Warning when an error occurs. Include the script line number, the line of code where the error occurred, and the full error record. For example:
Write-Warning "Error at Line '$($ex.InvocationInfo.ScriptLineNumber)': $($ex.InvocationInfo.Line). Error: $($ex.Exception.Message)"
Do not use Write-Error. It marks the action as failed after enforcement, even if the script sets $outputContext.Success to true, which indicates the action completed successfully.
Custom messages written to the Audit logs in the event of an error must include a user-friendly description of the issue.
Where the logs appear
Log messages appear in the Preview area of the script editor, under Logs.
When the script runs in production, it depends on the script type whether and where log messages are shown:
Log messages produced by Account scripts and Permission actions scripts are displayed when you View entitlement details.
The logging always include warnings and errors. Lower-level log messages such as information and debug messages are not retained during Enforcement runs, but they are retained when the script is started manually.
To start a script manually, Re-enforce an entitlement or Retry failed action.
Warning and error messages logged by a Resource create script appear when you Run with resources (Business > Evaluations > Logging tab).
Log messages produced by the Account data import script and Import permission memberships script are shown when you View target snapshot logs (Target > Snapshots > Logging tab).
Note
Process logs are retained for 30 days.