File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ function Get-Query ($srv = " localhost" ) {
2+ <#
3+ . SYNOPSIS
4+ Module using query.exe for created object powershell
5+ Does not depend on the localization of the OS
6+ . DESCRIPTION
7+ Example:
8+ Get-Query localhost # default
9+ Get-Query 192.168.1.1
10+ . LINK
11+ https://github.com/Lifailon/Get-Query
12+ https://github.com/Lifailon/Remote-Shadow-Administrator
13+ #>
14+ $Users = New-Object System.Collections.Generic.List[System.Object ]
15+ $query = query user / server:$srv
16+ if ($query -ne $null ) {
17+ $usr = $query [1 .. 100 ]
18+ $usr = $usr -replace " ^\s"
19+ $usr = $usr -replace " \s{2,100}" , " "
20+ $split1 = $usr -split " \n"
21+ foreach ($s in $split1 ) {
22+ $split2 = $s -split " \s"
23+ if ($split2.Count -eq 6 ) {
24+ $Users.Add ([PSCustomObject ]@ {
25+ Users = $split2 [0 ]
26+ Session = $null
27+ ID = $split2 [1 ]
28+ Status = $split2 [2 ]
29+ IdleTime = $split2 [3 ]
30+ LogonTime = $split2 [4 ]+ " " + $split2 [5 ]
31+ })
32+ }
33+ if ($split2.Count -eq 7 ) {
34+ $Users.Add ([PSCustomObject ]@ {
35+ User = $split2 [0 ]
36+ Session = $split2 [1 ]
37+ ID = $split2 [2 ]
38+ Status = $split2 [3 ]
39+ IdleTime = $split2 [4 ]
40+ LogonTime = $split2 [5 ]+ " " + $split2 [6 ]
41+ })
42+ }
43+ }
44+ $Users
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments