-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
OS.ps1
180 lines (162 loc) · 5.75 KB
/
OS.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#Requires -RunAsAdministrator
Clear-Host
#region User
Write-Output User
$PCName = @{
Name = "Computer name"
Expression = {$_.Name}
}
$Domain = @{
Name = "Domain"
Expression = {$_.Domain}
}
$UserName = @{
Name = "User Name"
Expression = {$_.UserName}
}
(Get-CimInstance -ClassName CIM_ComputerSystem | Select-Object -Property $PCName, $Domain, $UserName | Format-Table | Out-String).Trim()
Write-Output "`nLocal Users"
(Get-LocalUser | Out-String).Trim()
Write-Output "`nGroup Membership"
if ((Get-CimInstance -ClassName CIM_ComputerSystem).PartOfDomain -eq $true)
{
Get-ADPrincipalGroupMembership $env:USERNAME | Select-Object -Property Name
}
#endregion User
#region Operating System
Write-Output "`nOperating System"
$ProductName = @{
Name = "Product Name"
Expression = {$_.Caption}
}
$InstallDate = @{
Name = "Install Date"
Expression = {$_.InstallDate.Tostring().Split("")[0]}
}
$Arch = @{
Name = "Architecture"
Expression = {$_.OSArchitecture}
}
$OperatingSystem = Get-CimInstance -ClassName CIM_OperatingSystem | Select-Object -Property $ProductName, $InstallDate, $Arch
$Build = @{
Name = "Build"
Expression = {"$($_.CurrentMajorVersionNumber).$($_.CurrentMinorVersionNumber).$($_.CurrentBuild).$($_.UBR)"}
}
$CurrentVersion = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion" | Select-Object -Property $Build
([PSCustomObject] @{
"Product Name" = $OperatingSystem."Product Name"
"Install Date" = $OperatingSystem."Install Date"
Build = $CurrentVersion.Build
Architecture = $OperatingSystem.Architecture
} | Out-String).Trim()
#endregion Operating System
#region Registered apps
Write-Output "`nRegistered apps"
(Get-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*).DisplayName | Sort-Object
#endregion Registered apps
#region Updates
$HotFixID = @{
$Session = New-Object -ComObject Microsoft.Update.Session
Name = "KB ID"
Expression = {$_.HotFixID}
}
$InstalledOn = @{
Name = "Installed on"
Expression = {$_.InstalledOn.Tostring().Split("")[0]}
}
(Get-HotFix | Select-Object -Property $HotFixID, $InstalledOn -Unique | Format-Table | Out-String).Trim()
Write-Output "`nInstalled updates supplied by CBS"
$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$historyCount = $Searcher.GetTotalHistoryCount()
$KB = @{
Name = "KB ID"
Expression = {[regex]::Match($_.Title,"(KB[0-9]{6,7})").Value}
}
$Date = @{
Name = "Installed Date"
Expression = {$_.Date.Tostring().Split("") | Select-Object -Index 0}
}
($Searcher.QueryHistory(0, $historyCount) | Where-Object -FilterScript {
($_.Title -cmatch "KB") -and ($_.Title -notmatch "Defender") -and ($_.ResultCode -eq 2)
} | Select-Object $KB, $Date | Format-Table | Out-String).Trim()
#endregion Updates
#region Logical drives
Write-Output "`nLogical drives"
$Name = @{
Name = "Name"
Expression = {$_.DeviceID}
}
enum DriveType
{
RemovableDrive = 2
HardDrive = 3
}
$Type = @{
Name = "Drive Type"
Expression = {[System.Enum]::GetName([DriveType],$_.DriveType)}
}
$Size = @{
Name = "Size, GB"
Expression = {[math]::round($_.Size/1GB, 2)}
}
$FreeSpace = @{
Name = "FreeSpace, GB"
Expression = {[math]::round($_.FreeSpace/1GB, 2)}
}
(Get-CimInstance -ClassName Win32_LogicalDisk | Where-Object -FilterScript {$_.DriveType -ne 4} | Select-Object -Property $Name, $Type, $Size, $FreeSpace | Format-Table | Out-String).Trim()
#endregion Logical drives
#region Mapped disks
Write-Output "`nMapped disks"
(Get-SmbMapping | Select-Object -Property LocalPath, RemotePath | Format-Table | Out-String).Trim()
#endregion Mapped disks
#region Printers
Write-Output "`nPrinters"
Get-CimInstance -ClassName CIM_Printer | Select-Object -Property Name, Default, PortName, DriverName, ShareName | Format-Table
#endregion Printers
#region Network
Write-Output "`nDefault IP gateway"
(Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration).DefaultIPGateway
Write-Output "`nDNS"
(Get-DnsClientServerAddress -Family IPv4).ServerAddresses
#endregion Network
#region Microsoft Defender threats
Write-Output "`nMicrosoft Defender threats"
enum ThreatStatusID
{
Unknown = 0
Detected = 1
Cleaned = 2
Quarantined = 3
Removed = 4
Allowed = 5
Blocked = 6
QuarantineFailed = 102
RemoveFailed = 103
AllowFailed = 104
Abondoned = 105
BlockedFailed = 107
}
(Get-MpThreatDetection | ForEach-Object -Process {
[PSCustomObject] @{
"Detected Threats Paths" = $_.Resources
"ThreatID" = $_.ThreatID
"Status" = [System.Enum]::GetName([ThreatStatusID],$_.ThreatStatusID)
"Detection Time" = $_.InitialDetectionTime
}
} | Sort-Object ThreatID -Unique | Format-Table -AutoSize -Wrap | Out-String).Trim()
#endregion Microsoft Defender threats
#region Microsoft Defender settings
Write-Output "`nMicrosoft Defender settings"
(Get-MpPreference | ForEach-Object -Process {
[PSCustomObject] @{
"Excluded IDs" = $_.ThreatIDDefaultAction_Ids | Out-String
"Excluded Process" = $_.ExclusionProcess | Out-String
"Controlled Folder Access" = $_.EnableControlledFolderAccess | Out-String
"Controlled Folder Access Protected Folders" = $_.ControlledFolderAccessProtectedFolders | Out-String
"Controlled Folder Access Allowed Applications" = $_.ControlledFolderAccessAllowedApplications | Out-String
"Excluded Extensions" = $_.ExclusionExtension | Out-String
"Excluded Paths" = $_.ExclusionPath | Out-String
}
} | Format-List | Out-String).Trim()
#endregion Windows Defender settings