简体   繁体   English

远程用户的Powershell问题

[英]Powershell issue with remote users

I am looking to create a HTML page that contains a list of Blade workstations that are either in use or free. 我正在寻找一个HTML页面,其中包含正在使用或免费的Blade工作站列表。 So far via the web I have managed to find the following script but I am having an issue when trying to show the "Current Logged on User = None 到目前为止,我已经可以通过网络找到以下脚本,但是在尝试显示“当前登录用户=无”时遇到问题

The issue I am seeing is that the $user -eq $null will always place a "Current Logged On User: No one is currently logged on" 我看到的问题是$ user -eq $ null将始终放置“当前登录的用户:当前没有人登录”

see example 看例子

 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 } }​ 

The question is how to get $User -eq $Null working correctly 问题是如何使$ User -eq $ Null正常工作

You can see that it places a currently no one logged in when the line above say DE-Prod/simwa as the logged on user 当上面的行以DE-Prod / simwa作为登录用户时,您可以看到当前没有人登录

Hope that makes sense 希望有道理

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

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