Get User Running the App

avatar

Within an App I am trying to capture the User who is logged in to create an audit log of certain actions that the app does. but All I seem to get is the service account that PSU is running as.

can anyone point me in the right Direction?

avatar

Recommended Answer

@deroppi
Is this documented anywhere? How did you know what was in the $user variable or the $ClaimsPrincipal?

I feel like I'm missing out on some big book of documentation


@bcaydelotte
See: Variables | PowerShell Universal

All Comments (7)

avatar

Nevermind….. Finally got it working

avatar

Can you share the answer?

avatar

isn’t that just the $User variable?

And anything else should be in $claimsPrincipal.

    new-UDPage -Content { 
        $columns = @(
            New-UDTableColumn -Property Name
            New-UDTableColumn -Property Value
        )
        $var = @()
        $var += @{name = "User"; value = $User }
        $var += @{name = "Roles"; value = $Roles -join "," }
        $var += @{name = "PSUComputerName"; value = $PSUComputerName }
        $var += @{name = "$($ClaimsPrincipal.identity)"; value = ($ClaimsPrincipal.identity.name) }
        foreach ($item in $ClaimsPrincipal.claims) {
            $var += @{name = "$( ($item.type -split "claims")[-1] )"; value = "$($item.value)" }
        }
        New-UDTable -Data $var -Columns $columns -Title "logged on user account claims"
    } -Title "Home & CLAIMS" -Name "DEV HOME" -Icon @{ type='icon'; icon = 'igloo' }


avatar
isn’t that just the $User variable?

And anything else should be in $claimsPrincipal.
new-UDPage -Content {
$columns = @(
New-UDTableColumn -Property Name
New-UDTableColumn -Property Value
)
$var = @()
$var += @{name = "User"; value = $User }
$var += @{name = "Roles"; value = $Roles -join "," }
$var += @{name = "PSUComputerName"; value = $PSUComputerName }
$var += @{name = "$($ClaimsPrincipal.identity)"; value = ($ClaimsPrincipal.identity.name) }
foreach ($item in $ClaimsPrincipal.claims) {
$var += @{name = "$( ($item.type -split "claims")[-1] )"; value = "$($item.value)" }
}
New-UDTable -Data $var -Columns $columns -Title "logged on user account claims"
} -Title "Home & CLAIMS" -Name "DEV HOME" -Icon @{ type='icon'; icon = 'igloo' }


@deroppi
Is this documented anywhere? How did you know what was in the $user variable or the $ClaimsPrincipal?

I feel like I'm missing out on some big book of documentation

avatar

@bcaydelotte The session expired trigger is very reliable, even if delayed. It provides the identity as well as the IP address. If you don't want to clutter your dashboard, this is a solid option, in my opinion.

avatar
@deroppi
Is this documented anywhere? How did you know what was in the $user variable or the $ClaimsPrincipal?

I feel like I'm missing out on some big book of documentation


@bcaydelotte
See: Variables | PowerShell Universal

avatar

Well now I feel silly, I didn't scroll down enough.

Thank you!