Friday, May 13, 2022

Find the Current Logged On Username From a System Context using PowerShell

 

Sometimes we need to find the current logged on username from a system context.  For example, consider You need to deploy scripting using SCCM and Intune and you need to give folder permission to current user.

$usernamewithdomain = Get-WMIObject -class Win32_ComputerSystem | select -ExpandProperty PrimaryOwnerName

$usernamewithdomain