-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQuserIntoPSCustomObject.ps1
52 lines (52 loc) · 1.95 KB
/
QuserIntoPSCustomObject.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function Check-LogonSessions
{
[CmdletBinding()]
param (
[Parameter(HelpMessage = "ComputerName to check logon sessions",Position=0,ValueFromPipeline)]
[Alias("Computers")]
[string]$computerName
)
begin
{}
process
{
$userFromStationCSV=(quser /server:$computerName 2>&1) -split "\n" -replace '\s{2,}', ','
if ($userFromStationCSV -match "ID")
{
$userFromStationPSCustomObjects=($userFromStationCSV | convertfrom-csv -Delimiter ',')
foreach ($userFromStationPSCustomObject in $userFromStationPSCustomObjects)
{
if ($userFromStationPSCustomObject.STATE -like "Active")
{
[PScustomObject]@{
COMPUTERNAME=$computerName
USERNAME=$userFromStationPSCustomObject.USERNAME
SESSIONNAME=$userFromStationPSCustomObject.SESSIONNAME
ID=$userFromStationPSCustomObject.ID
STATE=$userFromStationPSCustomObject.STATE
IDLE_TIME=$userFromStationPSCustomObject."IDLE TIME"
LOGON_TIME=$userFromStationPSCustomObject."LOGON TIME"
}
}
else
{
[PScustomObject]@{
COMPUTERNAME=$computerName
USERNAME=$userFromStationPSCustomObject.USERNAME
SESSIONNAME="NOT AVAILABLE"
ID=$userFromStationPSCustomObject.SESSIONNAME
STATE=$userFromStationPSCustomObject.ID
IDLE_TIME=$userFromStationPSCustomObject.STATE
LOGON_TIME=$userFromStationPSCustomObject."IDLE TIME"
}
}
}
}
else
{
"Blad, lub zaden uzytkownik nie jest zalogowany"
}
}
end
{}
}