我希望创建一个HTML页面,其中包含正在使用或免费的Blade工作站列表。到目前为止,通过网络我已经设法找到以下脚本,但我在尝试显示“当前登录用户=无
时遇到问题我看到的问题是 $ user -eq $ null 将始终放置“当前登录用户:当前没有人登录”
参见示例
PC47295
DE-PROD\simwa
Current Logged On User: No one is currently logged on
Status: Online
$computers = Get-Content -Path c:\myscripts\computers.txt;
$Log = "C:\myscripts\usertest.txt"
$nl = [Environment]::NewLine
Get-date | Out-File $Log
foreach ($computer in $computers)
{
if (!($CompName = @(Get-WmiObject -ComputerName $computer -Namespace root\cimv2 -Class win32_ComputerSystem)[0].Name | Out-File $Log -Append))
{
#This gets the currently logged on user
$user = @(Get-WmiObject -ComputerName $computer -Namespace root\cimv2 -Class win32_ComputerSystem)[0].UserName | Out-File $Log -Append
#This loop is checking if anyone is logged on
if ($user -eq $null)
{
#This is returned if no one is logged on
"Current Logged On User: No one is currently logged on" | Out-File $Log -Append
}
else
{
#This is returned if a user is logged on
"Current Logged On User: " + $user | Out-File $Log -Append
}
"Status: Online" | Out-File $Log -Append
$nl | Out-File $Log -Append
}
}
答案 0 :(得分:0)
问题是如何让$ User -eq $ Null正常工作
当上面一行说DE-Prod / simwa作为登录用户时,你可以看到当前没有人登录
希望有意义