In a previous tip we used quser.exe to find the currently logged-on user on the local machine. Here is now a function that also allows us to find the currently logged-on user on a remote machine. As an extra benefit, the returned information is appended by a property called "ComputerName", so when you query multiple machines, you will know where the results came from:- function Get-LoggedOnUser
- {
- param([String[]]$ComputerName = $env:COMPUTERNAME)
-
- $ComputerName | ForEach-Object {
- (quser /SERVER:$_) -replace '\s{2,}', ',' |
- ConvertFrom-CSV |
- Add-Member -MemberType NoteProperty -Name ComputerName -Value $_ -PassThru
- }
- }
复制代码 http://powershell.com/cs/blogs/tips/archive/2014/01/15/finding-logged-on-user-on-remote-machine.aspx |