-
Notifications
You must be signed in to change notification settings - Fork 0
/
WinAudit0.1.ps1
392 lines (309 loc) · 19.8 KB
/
WinAudit0.1.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<#
.SYNOPSIS
Windows audit
.DESCRIPTION
This should help you to audit a virtual/physical windows machine without having to get into the nitty gritty of things.
.NOTES
File Name : winaudit0.1.ps1
Author : gajendra d ambi
Date : November 2015
Prerequisite : PowerShell v4+ over windows.
Copyright - None
0.0 : hostname,fqdn,domain,dns,timezone,ip,subnet,gateway,OS,description,storage,cpu,ram,applications,
0.1 : odbc, windows & SQL activation
.LINK
Script posted over: https://github.com/gajuambi/windows
#>
#Start of the script
$netbios = hostname.exe
$winaudit = "$PSScriptRoot\$netbios.html"
ni -ItemType file $winaudit -Force
#title
ac $winaudit '<table style="border:1px solid black" width=100% bgcolor="navy" cellspacing="0" cellpadding="0"><tr><td><font face="Impact,Candara,Algerian" size="9" color="white"><center>Windows Audit</center></font></td></tr></table><br>'
ac $winaudit '<!DOCTYPE html>'
ac $winaudit '<html>'
ac $winaudit '<head>'
ac $winaudit '<title>Windows Audit</title>'
ac $winaudit '</head>'
ac $winaudit '<body bgcolor="#E8E8E8">'
ac $winaudit '<table border=5px width="100%" cellspacing="0">'
#Section
Write-Host "collecting Section 1 : Windows Information"
ac $winaudit '<table style="border:1px solid black" width=100% bgcolor="#00518c" cellspacing="0" cellpadding="0"><tr><td><font face="Bookman,Palatino,Century Gothic,Verdana,Tahoma" size="3" color="white"><p><b>Section 1 : Windows Information</b></p></font></td></tr></table>'
#main table
ac $winaudit '<table style="border:1px solid black" width="100%" bgcolor="#e1e1e1" cellspacing="0" cellpadding="0"<TR><TD>'
#subtable
ac $winaudit '<table border="1px" width="100%" bgcolor="white" cellspacing="0" cellpadding="0">'
#colors from http://www.color-hex.com/
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Name</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Domain</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">OperatingSystem</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">activation</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Architecture</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Build</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Description</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">IP</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Subnet</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Gateway</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">DNS</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Timezone</font></th>'
$Name = $env:computername
$Domain = $env:userdnsdomain
$OperatingSystem = (gwmi Win32_OperatingSystem).Caption
$activation = (Get-CimInstance -ClassName SoftwareLicensingProduct | where ApplicationId -EQ 55c92734-d682-4d71-983e-d6ec3f16059f | where PartialProductKey).LicenseStatus
$Architecture = (gwmi Win32_OperatingSystem).OSArchitecture
$Build = (gwmi Win32_OperatingSystem).BuildNumber
$Description = (gwmi Win32_OperatingSystem).Description
$IP = (gwmi Win32_NetworkAdapterConfiguration | where IPAddress -ne $null).IPAddress
$Subnet = (gwmi Win32_NetworkAdapterConfiguration | where IPAddress -ne $null).IPSubnet
$Gateway = (gwmi Win32_NetworkAdapterConfiguration | where IPAddress -ne $null).DefaultIPGateway
$DNS = (gwmi Win32_NetworkAdapterConfiguration | where IPAddress -ne $null).DNSServerSearchOrder
$Timezone = ([System.TimeZone]::CurrentTimeZone).DaylightName
write-host "collecting basic information about the host $netbios" -foregroundcolor green
#start of a new row
ac $winaudit "<TR>"
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$Name</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$Domain</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$OperatingSystem</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$activation</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$Architecture</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$Build</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$Description</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$IP</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$Subnet</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$Gateway</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$DNS</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$Timezone</font></p>"
ac $winaudit "</TD>"
#end of row
ac $winaudit "</TR>"
#Ending & fixing the position of the table
ac $winaudit "</TD></TR></table>"
ac $winaudit "</table><P>"
ac $winaudit "<br><br>"
#Section
Write-Host "collecting Section 2 : Windows Configuration"
ac $winaudit '<table style="border:1px solid black" width=100% bgcolor="#00518c" cellspacing="0" cellpadding="0"><tr><td><font face="Bookman,Palatino,Century Gothic,Verdana,Tahoma" size="3" color="white"><p><b>Section 2 : Windows Configuration</b></p></font></td></tr></table>'
#main table
ac $winaudit '<table style="border:1px solid black" width="100%" bgcolor="#e1e1e1" cellspacing="0" cellpadding="0"<TR><TD>'
#subtable
ac $winaudit '<table border="1px" width="100%" bgcolor="white" cellspacing="0" cellpadding="0">'
#colors from http://www.color-hex.com/
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Name</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Ram</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Sockets</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Cores</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Users</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">DriveID</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Volumes</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Disksize[GB]</font></th>'
$Name = $env:computername
$Ram = [string]::Join(", ",(gwmi -class win32_physicalmemory | ForEach-Object {[math]::truncate($_.capacity / 1GB)}))
$Sockets = [string]::Join(", ",(gwmi -Class Win32_Processor).NumberOfLogicalProcessors)
$Cores = [string]::Join(", ",(gwmi -Class Win32_Processor).NumberOfCores)
$Users = [string]::Join(", ",(gwmi -Class Win32_UserAccount).Name)
$Volumecount = (gwmi Win32_LogicalDisk).count
write-host "collecting basic configuration of the host $netbios" -foregroundcolor green
#start of a new row
ac $winaudit "<TR>"
ac $winaudit "<TD style='border:1px solid black' align=left rowspan=$Volumecount>"
ac $winaudit "<p><font color='#196aa5'>$Name</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left rowspan=$Volumecount>"
ac $winaudit "<p><font color='#196aa5'>$Ram</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left rowspan=$Volumecount>"
ac $winaudit "<p><font color='#196aa5'>$Sockets</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left rowspan=$Volumecount>"
ac $winaudit "<p><font color='#196aa5'>$Cores</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left rowspan=$Volumecount>"
ac $winaudit "<p><font color='#196aa5'>$Users</font></p>"
ac $winaudit "</TD>"
foreach ($volume in (gwmi Win32_LogicalDisk).VolumeName) {
$DriveID = (gwmi Win32_LogicalDisk | where VolumeName -EQ $volume).DeviceID
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$DriveID</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$Volume</font></p>"
ac $winaudit "</TD>"
$Disksize = [math]::truncate((gwmi Win32_LogicalDisk | where VolumeName -EQ $volume).Size / 1GB)
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$Disksize</font></p>"
ac $winaudit "</TD>"
#end of row
ac $winaudit "</TR>"
}
#Ending & fixing the position of the table
ac $winaudit "</TD></TR></table>"
ac $winaudit "</table><P>"
ac $winaudit "<br><br>"
#Section 3
Write-Host "collecting Section 3 : Software"
ac $winaudit '<table style="border:1px solid black" width=100% bgcolor="#00518c" cellspacing="0" cellpadding="0"><tr><td><font face="Bookman,Palatino,Century Gothic,Verdana,Tahoma" size="3" color="white"><p><b>Section 3 : Software</b></p></font></td></tr></table>'
#main table
ac $winaudit '<table style="border:1px solid black" width="100%" bgcolor="#e1e1e1" cellspacing="0" cellpadding="0"<TR><TD>'
#subtable
ac $winaudit '<table border="1px" width="100%" bgcolor="white" cellspacing="0" cellpadding="0">'
#colors from http://www.color-hex.com/
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Computer</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Software</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Version</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Vendor</font></th>'
$count = ((Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | where Publisher -notlike "Microsoft*").DisplayName).count
$Computer = $env:computername
write-host "collecting the information about installed softwares (except those from microsoft) in $netbios" -foregroundcolor green
#start of a new row
ac $winaudit "<TR>"
ac $winaudit "<TD style='border:1px solid black' align=left rowspan=$count>"
ac $winaudit "<p><font color='#196aa5'>$Computer</font></p>"
ac $winaudit "</TD>"
foreach ($Software in (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | where Publisher -notlike "Microsoft*").DisplayName) {
$Version = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | where Publisher -notlike "Microsoft*" | where DisplayName -EQ $Software).DisplayVersion
$Vendor = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | where Publisher -notlike "Microsoft*" | where DisplayName -EQ $Software).Publisher
ac $winaudit "<TD style='border:1px solid black' align=left >"
ac $winaudit "<p><font color='#196aa5'>$Software</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left >"
ac $winaudit "<p><font color='#196aa5'>$Version</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left >"
ac $winaudit "<p><font color='#196aa5'>$Vendor</font></p>"
ac $winaudit "</TD>"
#end of row
ac $winaudit "</TR>"
}
#Ending & fixing the position of the table
ac $winaudit "</TD></TR></table>"
ac $winaudit "</table><P>"
ac $winaudit "<br><br>"
#Section 4
Write-Host "collecting Section 4 : ODBC"
if ((get-odbcdsn) -ne $null) {
ac $winaudit '<table style="border:1px solid black" width=100% bgcolor="#00518c" cellspacing="0" cellpadding="0"><tr><td><font face="Bookman,Palatino,Century Gothic,Verdana,Tahoma" size="3" color="white"><p><b>Section 4 : ODBC</b></p></font></td></tr></table>'
#main table
ac $winaudit '<table style="border:1px solid black" width="100%" bgcolor="#e1e1e1" cellspacing="0" cellpadding="0"<TR><TD>'
#subtable
ac $winaudit '<table border="1px" width="100%" bgcolor="white" cellspacing="0" cellpadding="0">'
#colors from http://www.color-hex.com/
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Name</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">DsnType</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Platform</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">DriverName</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Description</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Server</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Trusted_Connection</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Database</font></th>'
$Name = (get-odbcdsn).Name
$DsnType = (get-odbcdsn).DsnType
$Platform = (get-odbcdsn).Platform
$DriverName = (get-odbcdsn).DriverName
$Description = (get-odbcdsn).Attribute.Description
$Server = (get-odbcdsn).Attribute.Server
$Trusted_Connection = (get-odbcdsn).Attribute.Trusted_Connection
$Database = (get-odbcdsn).Attribute.Database
write-host "collecting the information about installed softwares (except those from microsoft) in $netbios" -foregroundcolor green
#start of a new row
ac $winaudit "<TR>"
ac $winaudit "<TD style='border:1px solid black' align=left rowspan=$count>"
ac $winaudit "<p><font color='#196aa5'>$Name</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left >"
ac $winaudit "<p><font color='#196aa5'>$DsnType</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left >"
ac $winaudit "<p><font color='#196aa5'>$Platform</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left >"
ac $winaudit "<p><font color='#196aa5'>$DriverName</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left >"
ac $winaudit "<p><font color='#196aa5'>$Description</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left >"
ac $winaudit "<p><font color='#196aa5'>$Server</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left >"
ac $winaudit "<p><font color='#196aa5'>$Trusted_Connection</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left >"
ac $winaudit "<p><font color='#196aa5'>$Database</font></p>"
ac $winaudit "</TD>"
#end of row
ac $winaudit "</TR>"
#Ending & fixing the position of the table
ac $winaudit "</TD></TR></table>"
ac $winaudit "</table><P>"
ac $winaudit "<br><br>"
}
if ((get-odbcdsn) -eq $null) {
ac $winaudit '<table style="border:1px solid black" width=100% bgcolor="#00518c" cellspacing="0" cellpadding="0"><tr><td><font face="Bookman,Palatino,Century Gothic,Verdana,Tahoma" size="3" color="white"><p><b><i>Section 4 : No ODBC<i></b></p></font></td></tr></table>'
ac $winaudit "<br><br>"
}
############################
#Section
Write-Host "Checking : SQL"
$instance = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL').((get-itemproperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances)
if ($instance -ne $null) {
ac $winaudit '<table style="border:1px solid black" width=100% bgcolor="#00518c" cellspacing="0" cellpadding="0"><tr><td><font face="Bookman,Palatino,Century Gothic,Verdana,Tahoma" size="3" color="white"><p><b>Section : SQL</b></p></font></td></tr></table>'
#main table
ac $winaudit '<table style="border:1px solid black" width="100%" bgcolor="#e1e1e1" cellspacing="0" cellpadding="0"<TR><TD>'
#subtable
ac $winaudit '<table border="1px" width="100%" bgcolor="white" cellspacing="0" cellpadding="0">'
#colors from http://www.color-hex.com/
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Computer</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Edition</font></th>'
ac $winaudit '<th style="border:1px solid black"><font face="Century Gothic,Verdana,Tahoma" color="black">Version</font></th>'
$Computer = $env:computername
$Edition = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$instance\Setup").Edition
$Version = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$instance\Setup").Version
write-host "collecting information about SQL in $netbios" -foregroundcolor green
#start of a new row
ac $winaudit "<TR>"
ac $winaudit "<TD style='border:1px solid black' align=left>"
ac $winaudit "<p><font color='#196aa5'>$Computer</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left >"
ac $winaudit "<p><font color='#196aa5'>$Edition</font></p>"
ac $winaudit "</TD>"
ac $winaudit "<TD style='border:1px solid black' align=left >"
ac $winaudit "<p><font color='#196aa5'>$Version</font></p>"
ac $winaudit "</TD>"
#end of row
ac $winaudit "</TR>"
#Ending & fixing the position of the table
ac $winaudit "</TD></TR></table>"
ac $winaudit "</table><P>"
ac $winaudit "<br><br>"
}
if ($instance -EQ $null) {
ac $winaudit '<table style="border:1px solid black" width=100% bgcolor="#00518c" cellspacing="0" cellpadding="0"><tr><td><font face="Bookman,Palatino,Century Gothic,Verdana,Tahoma" size="3" color="white"><p><b>No SQL Database found</b></p></font></td></tr></table>'
ac $winaudit "<br><br>"
}
#open the report
ii $winaudit