r/PowerShell • u/TechEUC-Atoofa • Oct 22 '26
Question Get current logged on User from System context script
I need to query the current logged on user and then write the info in HKLM registry for branding. Does anyone have a script or idea how this will work when the script is deployed from SCCM/Intune with System Context?
5
Upvotes
12
u/PinchesTheCrab Oct 22 '26 edited Oct 22 '26 •
Look for the owner(s) of explorer.exe processes.
6
u/trickiegt2 Oct 22 '26
'Quser' is my goto, shows active / inactive sessions, their ids & console / remote connection If I remember correctly quser is shorthand for queryuser
3
u/AcceptablePlay Oct 22 '26
I always had following lines to help me when in was still working with SCCM. First part should do the trick. Do test it, I'm on mobile and can't verify :)
$User = New-Object System.Security.Principal.NTAccount((Get-CimInstance -ClassName Win32_ComputerSystem).UserName)$UserSID = ($User.Translate([System.Security.Principal.SecurityIdentifier])).Value$LoggedOnUserProfilePath = Get-ItemPropertyValue -Path (Join-Path -Path 'Registry::HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList' -ChildPath $UserSid) -Name ProfileImagePath2
u/theballygickmongerer Oct 22 '26
You have SCCM, use the primary user from reports. You should be easily able to build a query and write the reg value.
1
u/Constant-Position601 Oct 23 '26
I have a script that finds this, but it’s using the outdated use of “Win32_Process”.
I was going to test using this:
Get-Process -Name explorer -IncludeUserName
1
u/ZovexUK Oct 24 '26
Does BGInfo not cover this, depending what you're using it for / branding