Public/Get-CurrentUserObject.ps1
Function Get-CurrentUserObject { <# .DESCRIPTION Search for an active user login and return the Username object .EXAMPLE $User = Get-CurrentUserObject .NOTES Created by: Jon Anderson Modified: 2023-07-10 #> Write-LogEntry -Value "Checking for an active user login" -Severity 1 $User = (Get-CimInstance -ClassName Win32_ComputerSystem).UserName if([String]::IsNullOrEmpty($User)) { Write-LogEntry -Value "No logged in user found" -Severity 1 Return $null } else { Write-LogEntry -Value "Found active user: $User" return $User } } |