2015-02-06 63 views
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 
 
     } 
 
} 
 

 
​

+0

什么问题......? – arco444 2015-02-06 16:26:09

回答

0

的问题是如何获得$ USER $ -eq空正常工作

你可以看到,它会将当前没有人登录时,上面的线说DE-PROD/simwa作为登录用户

希望有道理