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