繁体   English   中英

远程用户的Powershell问题

[英]Powershell issue with remote users

我正在寻找一个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 } }​ 

问题是如何使$ User -eq $ Null正常工作

当上面的行以DE-Prod / simwa作为登录用户时,您可以看到当前没有人登录

希望有道理

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM