PowerShell Script to get Current User SID

Script below to get the CU SID and save it to an environment variable called USERSID.

#——————————————————————————

# https://www.stadiacg.co.uk – 22-08-2019
# Script to get the SID of the Current Logged on User and save to environment variable
#——————————————————————————

# Get Username from CU Environment variable
$CurrentUser = Get-CU-SID ([Environment]::UserName)

# Parse Function to get SID
Set-Item -path env:USERSID -value ($CurrentUser)

# Set USERSID CU Environment variable
[Environment]::SetEnvironmentVariable(“USERSID”, $CurrentUser, “User”)

#——————————————————————————
# Function to get Current User SID
#——————————————————————————

function Get-CU-SID
{
Param ( $CUIdentity )
$MyID = new-object System.Security.Principal.NTAccount($CUIdentity)
return $MyID.Translate([System.Security.Principal.SecurityIdentifier]).toString()
}

#——————————————————————————

Enjoy

Woman working on a laptop in a modern office, with digital workplace performance dashboards showing
By Carl Schulze February 20, 2026
Learn how disciplined, evidence-led improvement can modernise complex digital workplaces, reduce disruption and improve user experience without destabilising existing services.
An IT dashboard shows healthy service metrics while a frustrated employee struggles at his laptop.
By Carl Schulze January 11, 2026
The monthly service report looks healthy.