PowerShell

Get Logged On User – From 4sysops.com Adam Bertram

Found this at 4sysops.com, and have been using it for a while, take a look at Adam’s post for the full run down.

function GetLoggedOnUser
{
   [CmdletBinding()]
   param
   (
       [Parameter()]
       [ValidateScript({ TestConnection ComputerName $_ Quiet Count 1 })]
       [ValidateNotNullOrEmpty()]
       [string[]]$ComputerName = $env:COMPUTERNAME
   )
   foreach ($comp in $ComputerName)
   {
       $output = @{ ‘ComputerName’ = $comp }
       $output.UserName = (GetWmiObject Class win32_computersystem ComputerName $comp).UserName
       [PSCustomObject]$output
   }
}
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment