0
我正在創建一個HTML頁面,其中包含正在使用或免費使用的刀片式工作站列表。到目前爲止,通過網絡我已經設法找到以下腳本,但我試圖顯示「當前登錄用戶=無遠程用戶的Powershell問題
問題我看到的是$ 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
}
}
什麼問題......? – arco444 2015-02-06 16:26:09