Hello.
I am trying to work out if there is a way to correlate from logs the log entries to specific users\processes...
i.e
APP --> SCRIPT How do I correlate the log entries from the APP with the log entries from the SCRIPT...
Is this possible?
I am struggling to see how I can correlate entries to specific user\process runs...
Am I missing something?
Hello Allan,
Thank you for the clear question.
You are not missing anything.
PowerShell Universal does not add a shared correlation ID that links an app event to the job it starts.
Apps and jobs write their own log lines, so your code has to carry the link.
All the pieces you need are available as built-in variables.
In an app, $User holds the signed-in user and $DashboardName holds the app name.
In a script, $UAJob.Id holds the job ID and $UAJob.Identity.Name holds the user who started the job.
The simplest pattern is to create an ID in the app, pass it to the script, and write it in every log line on both sides.
Here is the app side:
New-UDButton -Text 'Run report' -OnClick {
$CorrelationId = [guid]::NewGuid().ToString()
$Job = Invoke-PSUScript -Name 'MyScript.ps1' -Integrated -Parameters @{
CorrelationId = $CorrelationId
CallingUser = $User
} -Notes "App=$DashboardName User=$User CorrelationId=$CorrelationId"
Write-PSULog -Feature 'App' -Resource $DashboardName -Level Information -Message "CorrelationId=$CorrelationId User=$User App=$DashboardName started job $($Job.Id)"
}
Here is the script side:
param(
[string]$CorrelationId,
[string]$CallingUser
)
Write-PSULog -Feature 'Script' -Resource 'MyScript.ps1' -Level Information -Message "CorrelationId=$CorrelationId User=$CallingUser Job=$($UAJob.Id) started"
# ... your work ...
Write-PSULog -Feature 'Script' -Resource 'MyScript.ps1' -Level Information -Message "CorrelationId=$CorrelationId User=$CallingUser Job=$($UAJob.Id) finished"
You can then search for that ID in Observe > Logging > Live Logs, or in the User log file, to see the app line and the script lines together.
The -Notes value is also stored with the job, so the run itself carries the app, the user and the ID.
If you add -Wait, the cmdlet returns the script output instead of the job object, but the shared ID still links both sides.
A few tips will save you time:
Pass $User from the app as a parameter, instead of relying on $UAJob.Identity, so the script always sees the person who clicked.
Put the values straight into -Message with normal PowerShell string expansion, as in the example.
The -Properties parameter is accepted, but its values do not show as separate fields in the built-in log view, so string expansion is the safer choice for now.
If you send logs to a File, Database, TCP or HTTP target, set its Scope to User so the Write-PSULog lines reach it.
Could you tell me which PowerShell Universal version you are running?
Version 2026.2.4 fixed some cases where Write-PSULog lines went to the system log instead of a User target (tickets PSU-947 and PSU-296, for internal reference only).
Knowing your version lets me confirm the example behaves the same way on your server.
Here are the related pages:
https://docs.devolutions.net/powershell-universal/development/logging
https://docs.devolutions.net/powershell-universal/platform/variables
https://docs.devolutions.net/powershell-universal/powershell-commands/write-psulog
https://docs.devolutions.net/powershell-universal/powershell-commands/invoke-psuscript
Best regards,
Patrick Ouimet
Hi Patrick,
Thanks this explains a lot, I did a whole bunch of digging into all variables that are available in each space to see if i could find anything that I could use... :) I didnot.. Which you have now confirmed above. I did start building up a correlation ID solution passing it around... APP--> API\Script etc.. API call via a header entry... Script via params..
I got pulled into other things so hence my delay in my response.
Good\Bad to get confirmation that I am not missing something :)
I am using 2026.3.3.
Thanks
Allan
Hello Allan,
Thank you for the update and for confirming your version.
Before replying, I tested the whole chain on a 2026.3.3 server, and I need to correct one point from my first example.
Leave out -Integrated when you call Invoke-PSUScript from an app or an API.
In 2026.3.3, the default security model is Strict.
In that mode, PowerShell Universal blocks calls that use -Integrated with "Permission denied", even for administrators.
Without -Integrated, the call runs as the signed-in user or the API caller, and it worked in all three security models.
That user needs permission to run the script, and the API endpoint needs authentication turned on.
This also applies to the app example from my first reply, so remove -Integrated there and keep the rest.
Your plan to pass the ID to the API in a header is a good fit.
APIs have a few built-in variables that help here.
$Headers holds the request headers, but lookups in it are case-sensitive.
Copy it into a hashtable first, as in the example below, so the header name matches in any case.
$RequestId holds a unique ID for each request, so you can use it when the header is missing.
$Identity holds the name of the caller.
If the app calls the API with a shared app token, $Identity shows the account that owns that token, not the person who clicked.
In that case, send the app user in a header as well.
Here is the endpoint example, tested on 2026.3.3:
# $Headers is case-sensitive, a PowerShell hashtable is not
$RequestHeaders = @{}
foreach ($Key in $Headers.Keys) { $RequestHeaders[$Key] = $Headers[$Key] }
$CorrelationId = $RequestHeaders['X-Correlation-Id']
if (-not $CorrelationId) { $CorrelationId = $RequestId }
$CallingUser = $RequestHeaders['X-Calling-User']
if (-not $CallingUser) { $CallingUser = $Identity }
Write-PSULog -Feature 'API' -Resource '/report' -Level Information -Message "CorrelationId=$CorrelationId User=$CallingUser RequestId=$RequestId received"
$Job = Invoke-PSUScript -Name 'Script1.ps1' -Parameters @{
CorrelationId = $CorrelationId
CallingUser = $CallingUser
} -Notes "API=/report User=$CallingUser CorrelationId=$CorrelationId"
New-PSUApiResponse -StatusCode 200 -Headers @{ 'X-Correlation-Id' = $CorrelationId } -Body (@{ CorrelationId = $CorrelationId; JobId = $Job.Id } | ConvertTo-Json)
The endpoint sends the ID back in a response header, so the caller can log the same value.
The -Notes value also stores the ID with the job.
In my tests, the API line and the script lines with the same ID all landed together in the default User log file.
I will also share your use case with our product team as a request for a built-in correlation ID.
Let me know if you have any other questions, otherwise I will close this case in a few days.
Here are the related pages:
https://docs.devolutions.net/powershell-universal/platform/variables
https://docs.devolutions.net/powershell-universal/development/logging
https://docs.devolutions.net/powershell-universal/config/module
https://docs.devolutions.net/powershell-universal/powershell-commands/new-psuapiresponse
Best regards,
Patrick Ouimet