368d6fafea
Code backup
22 lines
622 B
PowerShell
22 lines
622 B
PowerShell
function Get-LoggedUser
|
|
{
|
|
[CmdletBinding()]
|
|
param
|
|
(
|
|
[string[]]$ComputerName
|
|
)
|
|
foreach ($comp in $ComputerName)
|
|
{
|
|
if ((Test-NetConnection $comp -WarningAction SilentlyContinue).PingSucceeded -eq $true)
|
|
{
|
|
$output = @{'Computer' = $comp }
|
|
$output.UserName = (Get-WmiObject -Class win32_computersystem -ComputerName $comp).UserName
|
|
}
|
|
else
|
|
{
|
|
$output = @{'Computer' = $comp }
|
|
$output.UserName = "offline"
|
|
}
|
|
[PSCustomObject]$output
|
|
}
|
|
} |