我想知道是否可以获得远程login用户在计算机上的当前用户名? 从Windows CMD?
种类:WMIC / NODE:ComputerName ComputerSystem获取用户名
此命令可以正常工作,但会将本地用户login到ComputerName。 不是那些远程login的人。
感谢您的帮助!
我使用这个为我的环境,稍微修改,只是拉我只想要的电脑filter。 它在去年的某个时候出现了,我认为…在2008 R2上对我来说足够好。 2012年虽然没有testing过。 我只是计划每天运行。
http://gallery.technet.microsoft.com/scriptcenter/PowerShell-script-to-Find-d2ba4252
# Import the Active Directory module for the Get-ADComputer CmdLet Import-Module ActiveDirectory # Get today's date for the report $today = Get-Date # Setup email parameters $subject = "ACTIVE SERVER SESSIONS REPORT - " + $today $priority = "Normal" $smtpServer = "YourMailServer" $emailFrom = "[email protected]" $emailTo = "[email protected]" # Create a fresh variable to collect the results. You can use this to output as desired $SessionList = "ACTIVE SERVER SESSIONS REPORT - " + $today + "`n`n" # Query Active Directory for computers running a Server operating system $Servers = Get-ADComputer -Filter {OperatingSystem -like "*server*"} # Loop through the list to query each server for login sessions ForEach ($Server in $Servers) { $ServerName = $Server.Name # When running interactively, uncomment the Write-Host line below to show which server is being queried # Write-Host "Querying $ServerName" # Run the qwinsta.exe and parse the output $queryResults = (qwinsta /server:$ServerName | foreach { (($_.trim() -replace "\s+",","))} | ConvertFrom-Csv) # Pull the session information from each instance ForEach ($queryResult in $queryResults) { $RDPUser = $queryResult.USERNAME $sessionType = $queryResult.SESSIONNAME # We only want to display where a "person" is logged in. Otherwise unused sessions show up as USERNAME as a number If (($RDPUser -match "[az]") -and ($RDPUser -ne $NULL)) { # When running interactively, uncomment the Write-Host line below to show the output to screen # Write-Host $ServerName logged in by $RDPUser on $sessionType $SessionList = $SessionList + "`n`n" + $ServerName + " logged in by " + $RDPUser + " on " + $sessionType } } } # Send the report email Send-MailMessage -To $emailTo -Subject $subject -Body $SessionList -SmtpServer $smtpServer -From $emailFrom -Priority $priority # When running interactively, uncomment the Write-Host line below to see the full list on screen $SessionList
由于其他人都在这个帽子上,我想我也可以。
我一直在使用@TheCleaner提供的qwinsta.exe来监视terminal服务器上的活动用户,但只输出文本。
但是我最近发现了Win32_UserProfile类,它非常有希望,因为我现在可以在PS中使用对象输出。
这是我到目前为止:
Get-WmiObject Win32_Profile -ComputerName $Name -Filter "Loaded='True'" | Foreach {$_.LocalPath}
**注意:您可能需要通过放弃$ _。LocalPath值不在C:\ Users文件夹中的所有结果来筛选一些“加载的”configuration文件。
如果不需要从cmd运行…我使用称为NetScan的一个很棒的小工具为我做这个。
NetScan链接
一个简单的解决scheme是枚举运行在远程主机上的EXPLORER.EXE实例。 然后,只需拉动拥有的用户。
示例PS命令:
Get-WmiObject -Class Win32_Process -Filter "Name='explorer.exe'" -ComputerName "REMOTECOMPUTER" | ForEach-Object{ "{0}\{1}" -f $_.GetOwner().Domain, $_.GetOwner().User }