-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-ADComputer lastLogon.ps1
60 lines (57 loc) · 2.73 KB
/
Get-ADComputer lastLogon.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
53
54
55
56
57
58
59
60
function ConvertTo-OperatingSystem {
[CmdletBinding()]
param(
[string] $OperatingSystem,
[string] $OperatingSystemVersion
)
if ($OperatingSystem -like 'Windows 10*') {
$Systems = @{
'10.0 (19041)' = "Windows 10 2004"
'10.0 (18363)' = "Windows 10 1909"
'10.0 (18362)' = "Windows 10 1903"
'10.0 (17763)' = "Windows 10 1809"
'10.0 (17134)' = "Windows 10 1803"
'10.0 (16299)' = "Windows 10 1709"
'10.0 (15063)' = "Windows 10 1703"
'10.0 (14393)' = "Windows 10 1607"
'10.0 (10586)' = "Windows 10 1511"
'10.0 (10240)' = "Windows 10 1507"
}
$System = $Systems[$OperatingSystemVersion]
}
elseif ($OperatingSystem -notlike 'Windows 10*') {
$System = $OperatingSystem
}
if ($System) { $System }
else { 'Unknown' }
}
# change only use enabled computers
# $Computers = Get-ADComputer -Filter * -properties Name, OperatingSystem, OperatingSystemVersion, LastLogonDate, whenCreated
$Computers = Get-ADComputer -Filter 'enabled -eq "true"' -properties Name, OperatingSystem, OperatingSystemVersion, LastLogonDate, whenCreated
$ComputersDisabled = Get-ADComputer -Filter 'enabled -ne "true"' -properties Name, OperatingSystem, OperatingSystemVersion, LastLogonDate, whenCreated
$ComputerList = foreach ($_ in $Computers) {
[PSCustomObject] @{
Name = $_.Name
DistinguishedName = $_.DistinguishedName
OperatingSystem = $_.OperatingSystem
OperatingSystemVersion = $_.OperatingSystemVersion
System = ConvertTo-OperatingSystem -OperatingSystem $_.OperatingSystem -OperatingSystemVersion $_.OperatingSystemVersion
LastLogonDate = $_.LastLogonDate
WhenCreated = $_.WhenCreated
}
}
$ComputerListDisabled = foreach ($_ in $ComputersDisabled) {
[PSCustomObject] @{
Name = $_.Name
DistinguishedName = $_.DistinguishedName
OperatingSystem = $_.OperatingSystem
OperatingSystemVersion = $_.OperatingSystemVersion
System = ConvertTo-OperatingSystem -OperatingSystem $_.OperatingSystem -OperatingSystemVersion $_.OperatingSystemVersion
LastLogonDate = $_.LastLogonDate
WhenCreated = $_.WhenCreated
}
}
# list enabled computers
#$ComputerList | Sort-Object LastLogonDate | Format-Table -AutoSize
$ComputerList | Sort-Object LastLogonDate | Out-GridView #Export-Csv ComputersEnabledByLastLogon.csv
$ComputerListDisabled | Sort-Object LastLogonDate | Out-GridView #Export-Csv ComputersDisabledByLastLogon.csv