@@ -46,7 +46,6 @@ Set-StrictMode -Version latest;
46
46
47
47
# Import-Module "sqlps" -DisableNameChecking -erroraction SilentlyContinue
48
48
Import-Module " .\LoadSQLSMO"
49
- Import-Module " .\Get-ProductKey.psm1"
50
49
LoadSQLSMO
51
50
52
51
@@ -68,8 +67,6 @@ Write-Output "Server $SQLInstance"
68
67
$WinServer = ($SQLInstance -split {$_ -eq " ," -or $_ -eq " \" })[0 ]
69
68
70
69
71
- # Test Get Product-Key
72
- $ProdKey = Get-ProductKey - Computername $winserver
73
70
74
71
# Server connection check
75
72
[string ]$serverauth = " win"
@@ -121,10 +118,6 @@ if(!(test-path -path $fullfolderPath))
121
118
}
122
119
123
120
124
- # Load SMO Assemblies
125
- Import-Module " .\LoadSQLSmo.psm1"
126
- LoadSQLSMO
127
-
128
121
# Set Local Vars
129
122
[string ]$server = $SQLInstance
130
123
@@ -228,34 +221,31 @@ $mystring | out-file $fullFileName -Encoding ascii -Append
228
221
$mystring = " OS Platform: " + $srv.Platform
229
222
$mystring | out-file $fullFileName - Encoding ascii - Append
230
223
231
- $mystring = " OS Product Key: " + $ProdKey.ProductKey
232
- $mystring | out-file $fullFileName - Encoding ascii - Append
233
-
234
-
235
224
236
225
# Turn off default Error Handler for WMI
237
226
$old_ErrorActionPreference = $ErrorActionPreference
238
227
$ErrorActionPreference = ' SilentlyContinue'
239
228
240
- $mystring = Get-WmiObject –class Win32_OperatingSystem - ComputerName $server | select Name, BuildNumber, BuildType, CurrentTimeZone, InstallDate, SystemDrive, SystemDevice, SystemDirectory
229
+ $mystring2 = Get-WmiObject –class Win32_OperatingSystem - ComputerName $server | select Name, BuildNumber, BuildType, CurrentTimeZone, InstallDate, SystemDrive, SystemDevice, SystemDirectory
241
230
242
231
# Reset default PS error handler
243
232
$ErrorActionPreference = $old_ErrorActionPreference
244
233
245
- if ( $mystring -ne $null )
234
+ try
246
235
{
247
- Write-output (" OS Host Name: {0} " -f $mystring .Name )| out-file $fullFileName - Encoding ascii - Append
248
- Write-output (" OS BuildNumber: {0} " -f $mystring .BuildNumber )| out-file $fullFileName - Encoding ascii - Append
249
- Write-output (" OS Buildtype: {0} " -f $mystring .BuildType )| out-file $fullFileName - Encoding ascii - Append
250
- Write-output (" OS CurrentTimeZone: {0}" -f $mystring .CurrentTimeZone )| out-file $fullFileName - Encoding ascii - Append
251
- Write-output (" OS InstallDate: {0} " -f $mystring .InstallDate )| out-file $fullFileName - Encoding ascii - Append
252
- Write-output (" OS SystemDrive: {0} " -f $mystring .SystemDrive )| out-file $fullFileName - Encoding ascii - Append
253
- Write-output (" OS SystemDevice: {0} " -f $mystring .SystemDevice )| out-file $fullFileName - Encoding ascii - Append
254
- Write-output (" OS SystemDirectory: {0} " -f $mystring .SystemDirectory )| out-file $fullFileName - Encoding ascii - Append
236
+ Write-output (" OS Host Name: {0} " -f $mystring2 .Name )| out-file $fullFileName - Encoding ascii - Append
237
+ Write-output (" OS BuildNumber: {0} " -f $mystring2 .BuildNumber )| out-file $fullFileName - Encoding ascii - Append
238
+ Write-output (" OS Buildtype: {0} " -f $mystring2 .BuildType )| out-file $fullFileName - Encoding ascii - Append
239
+ Write-output (" OS CurrentTimeZone: {0}" -f $mystring2 .CurrentTimeZone )| out-file $fullFileName - Encoding ascii - Append
240
+ Write-output (" OS InstallDate: {0} " -f $mystring2 .InstallDate )| out-file $fullFileName - Encoding ascii - Append
241
+ Write-output (" OS SystemDrive: {0} " -f $mystring2 .SystemDrive )| out-file $fullFileName - Encoding ascii - Append
242
+ Write-output (" OS SystemDevice: {0} " -f $mystring2 .SystemDevice )| out-file $fullFileName - Encoding ascii - Append
243
+ Write-output (" OS SystemDirectory: {0} " -f $mystring2 .SystemDirectory )| out-file $fullFileName - Encoding ascii - Append
255
244
}
256
- else
245
+ catch
257
246
{
258
- Write-output " WMI Call to Win32_OperatingSystem class failed " | out-file $fullFileName - Encoding ascii - Append
247
+ Write-output " Error getting OS specs via WMI - WMI/firewall issue?" | out-file $fullFileName - Encoding ascii - Append
248
+ Write-output " Error getting OS specs via WMI - WMI/firewall issue?"
259
249
}
260
250
261
251
" " | out-file $fullFileName - Encoding ascii - Append
@@ -265,68 +255,67 @@ else
265
255
$old_ErrorActionPreference = $ErrorActionPreference
266
256
$ErrorActionPreference = ' SilentlyContinue'
267
257
268
- $mystring = Get-WmiObject - class Win32_Computersystem - ComputerName $server | select manufacturer
258
+ $mystring3 = Get-WmiObject - class Win32_Computersystem - ComputerName $server | select manufacturer
269
259
270
260
# Reset default PS error handler
271
261
$ErrorActionPreference = $old_ErrorActionPreference
272
262
273
- if ( $mystring -ne $null )
263
+ try
274
264
{
275
- Write-output (" HW Manufacturer: {0} " -f $mystring .Manufacturer )| out-file $fullFileName - Encoding ascii - Append
265
+ Write-output (" HW Manufacturer: {0} " -f $mystring3 .Manufacturer )| out-file $fullFileName - Encoding ascii - Append
276
266
}
277
- else
267
+ catch
278
268
{
279
- Write-output " WMI Call to Win32_Computersystem class failed " | out-file $fullFileName - Encoding ascii - Append
269
+ Write-output " Error getting Hardware specs via WMI - WMI/firewall issue? " | out-file $fullFileName - Encoding ascii - Append
270
+ Write-output " Error getting Hardware specs via WMI - WMI/firewall issue? "
280
271
}
281
272
273
+ " " | out-file $fullFileName - Encoding ascii - Append
274
+
282
275
# Turn off default Error Handler for WMI
283
276
$old_ErrorActionPreference = $ErrorActionPreference
284
277
$ErrorActionPreference = ' SilentlyContinue'
285
278
286
- $mystring = Get-WmiObject –class Win32_processor - ComputerName $server | select Name, NumberOfCores, NumberOfLogicalProcessors
279
+ $mystring4 = Get-WmiObject –class Win32_processor - ComputerName $server | select Name, NumberOfCores, NumberOfLogicalProcessors
287
280
288
281
# Reset default PS error handler
289
282
$ErrorActionPreference = $old_ErrorActionPreference
290
283
291
- if ( $mystring -ne $null )
284
+ try
292
285
{
293
- Write-output (" HW Processor: {0} " -f $mystring .Name )| out-file $fullFileName - Encoding ascii - Append
294
- Write-Output (" HW CPUs: {0}" -f $mystring .NumberOfLogicalProcessors )| out-file $fullFileName - Encoding ascii - Append
295
- Write-output (" HW Cores: {0}" -f $mystring .NumberOfCores )| out-file $fullFileName - Encoding ascii - Append
286
+ Write-output (" HW Processor: {0} " -f $mystring4 .Name )| out-file $fullFileName - Encoding ascii - Append
287
+ Write-Output (" HW CPUs: {0}" -f $mystring4 .NumberOfLogicalProcessors )| out-file $fullFileName - Encoding ascii - Append
288
+ Write-output (" HW Cores: {0}" -f $mystring4 .NumberOfCores )| out-file $fullFileName - Encoding ascii - Append
296
289
}
297
- else
290
+ catch
298
291
{
299
- Write-output " WMI Call to Win32_processor class failed " | out-file $fullFileName - Encoding ascii - Append
292
+ Write-output " Error getting CPU specs via WMI - WMI/Firewall issue? " | out-file $fullFileName - Encoding ascii - Append
293
+ Write-output " Error getting CPU specs via WMI - WMI/Firewall issue? "
300
294
}
301
295
302
- <#
303
- Use WMI: 2008 doesnt have System Mainboard String in the Log
304
- $mystring = $srv.ReadErrorLog(0) | where-object {$_.Text -like "System*"} |select text
305
- "HW Mainboard/Model: " + $mystring.text | out-file $fullFileName -Encoding ascii -Append
306
- #>
307
-
296
+ " " | out-file $fullFileName - Encoding ascii - Append
308
297
309
- $mystring = " `r`n SQL Build reference: http://sqlserverbuilds.blogspot.com/ "
310
- $mystring | out-file $fullFileName - Encoding ascii - Append
298
+ $mystring5 = " `r`n SQL Build reference: http://sqlserverbuilds.blogspot.com/ "
299
+ $mystring5 | out-file $fullFileName - Encoding ascii - Append
311
300
312
- $mystring = " `r`n SQL Build reference: http://sqlserverupdates.com/ "
313
- $mystring | out-file $fullFileName - Encoding ascii - Append
301
+ $mystring5 = " `r`n SQL Build reference: http://sqlserverupdates.com/ "
302
+ $mystring5 | out-file $fullFileName - Encoding ascii - Append
314
303
315
304
316
- $mystring = " `r`n More Detailed Diagnostic Queries here:`r`n http://www.sqlskills.com/blogs/glenn/sql-server-diagnostic-information-queries-for-september-2015"
317
- $mystring | out-file $fullFileName - Encoding ascii - Append
305
+ $mystring5 = " `r`n More Detailed Diagnostic Queries here:`r`n http://www.sqlskills.com/blogs/glenn/sql-server-diagnostic-information-queries-for-september-2015"
306
+ $mystring5 | out-file $fullFileName - Encoding ascii - Append
318
307
319
308
# Dump out loaded DLLs
320
309
$mySQLquery = " select * from sys.dm_os_loaded_modules order by name"
321
310
322
311
# connect correctly
323
312
if ($serverauth -eq " win" )
324
313
{
325
- $sqlresults = Invoke-SqlCmd - ServerInstance $SQLInstance - Query $mySQLquery - QueryTimeout 10 - erroraction SilentlyContinue
314
+ $sqlresults2 = Invoke-SqlCmd - ServerInstance $SQLInstance - Query $mySQLquery - QueryTimeout 10 - erroraction SilentlyContinue
326
315
}
327
316
else
328
317
{
329
- $sqlresults = Invoke-SqlCmd - ServerInstance $SQLInstance - Query $mySQLquery - Username $myuser - Password $mypass - QueryTimeout 10 - erroraction SilentlyContinue
318
+ $sqlresults2 = Invoke-SqlCmd - ServerInstance $SQLInstance - Query $mySQLquery - Username $myuser - Password $mypass - QueryTimeout 10 - erroraction SilentlyContinue
330
319
}
331
320
332
321
# Create some CSS for help in column formatting during HTML exports
@@ -368,7 +357,7 @@ if(!(test-path -path "$fullfolderPath\HTMLReport.css"))
368
357
}
369
358
370
359
$RunTime = Get-date
371
- $sqlresults | select file_version, product_version, debug, patched, prerelease, private_build, special_build, language, company, description, name `
360
+ $sqlresults2 | select file_version, product_version, debug, patched, prerelease, private_build, special_build, language, company, description, name `
372
361
| ConvertTo-Html - PostContent " <h3>Ran on : $RunTime </h3>" - PreContent " <h1>$SqlInstance </H1><H2>Loaded DLLs</h2>" - CSSUri " HtmlReport.css" | Set-Content " $fullfolderPath \02_Loaded_Dlls.html"
373
362
374
363
@@ -378,20 +367,16 @@ $mySQLquery2= "dbcc tracestatus()"
378
367
# connect correctly
379
368
if ($serverauth -eq " win" )
380
369
{
381
- $sqlresults2 = Invoke-SqlCmd - ServerInstance $SQLInstance - Query $mySQLquery2 - QueryTimeout 10 - erroraction SilentlyContinue
370
+ $sqlresults3 = Invoke-SqlCmd - ServerInstance $SQLInstance - Query $mySQLquery2 - QueryTimeout 10 - erroraction SilentlyContinue
382
371
}
383
372
else
384
373
{
385
- $sqlresults2 = Invoke-SqlCmd - ServerInstance $SQLInstance - Query $mySQLquery2 - Username $myuser - Password $mypass - QueryTimeout 10 - erroraction SilentlyContinue
374
+ $sqlresults3 = Invoke-SqlCmd - ServerInstance $SQLInstance - Query $mySQLquery2 - Username $myuser - Password $mypass - QueryTimeout 10 - erroraction SilentlyContinue
386
375
}
387
376
388
- if ($sqlresults2 -eq $null )
389
- {
390
-
391
- }
392
- else
377
+ if ($sqlresults3 -ne $null )
393
378
{
394
- $sqlresults2 | select TraceFlag, Status, Global, Session | ConvertTo-Html - PostContent " <h3>Ran on : $RunTime </h3>" - PreContent " <h1>$SqlInstance </H1><H2>Trace Flags</h2>" - CSSUri " HtmlReport.css" | Set-Content " $fullfolderPath \03_Trace_Flags.html"
379
+ $sqlresults3 | select TraceFlag, Status, Global, Session | ConvertTo-Html - PostContent " <h3>Ran on : $RunTime </h3>" - PreContent " <h1>$SqlInstance </H1><H2>Trace Flags</h2>" - CSSUri " HtmlReport.css" | Set-Content " $fullfolderPath \03_Trace_Flags.html"
395
380
}
396
381
397
382
0 commit comments