forked from mmessano/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathGet-MSSQL-ServerAttrib-Html.ps1
76 lines (65 loc) · 2.46 KB
/
Get-MSSQL-ServerAttrib-Html.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
## =====================================================================
## Title : Get-MSSQL-ServerAttrib-Html
## Description : Connect to SQL Server and output server attributes to HTML
## Author : Idera
## Date : 9/1/2008
## Input : -serverInstance <server\instance>
## -tempDir <file path>
## -verbose
## -debug
## Output :
## Usage : PS> . Get-MSSQL-ServerAttrib-Html -serverInstance MyServer
## -tempDir C:\TEMP\ -v -d
## Notes :
## Tag : SQL Server, Attributes, HTML
## Change log :
## =====================================================================
param
(
[string]$serverInstance = "(local)",
[string]$tempDir = "C:\Dexma\TEMP\",
[switch]$verbose,
[switch]$debug
)
function main()
{
if ($verbose) {$VerbosePreference = "Continue"}
if ($debug) {$DebugPreference = "Continue"}
Get-MSSQL-ServerAttrib-Html $serverInstance $tempDir
}
function Get-MSSQL-ServerAttrib-Html($serverInstance, $tempDir)
{
$outputFile = $tempDir + "SQLServerAttributes.html"
Write-Debug "Output directory: $outputFile"
# Validate path to temp directory
if (-not (Test-Path -path $tempDir))
{
Write-Host Unable to validate path to temp directory: $tempDir
break
}
# Load-SMO assemblies
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlEnum")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo")
# Create a Server object for default instance
Write-Debug "Connecting to server: $ServerInstance"
$namedInstance = New-Object ('Microsoft.SqlServer.Management.Smo.Server') ($serverInstance)
# Get server attributes and convert attribute info to HTML
# Save to file and overwrite the file if it exists
Write-Debug "Saving $outputFile..."
# TIP: using PowerShell convert an output stream to formatted HTML
$namedInstance.EnumServerAttributes() | `
convertto-html -property attribute_name, attribute_value `
-title "Server Attributes" -body '<font face="Verdana">' `
| foreach {$_ -replace "<th>", "<th align=left>"} `
| Out-File $outputFile
# TIP: Open new browser window and display ServerAttributes.html
# requires confirmation
invoke-item $outputFile -confirm
# Cleanup
remove-variable namedInstance
remove-variable tempDir
remove-variable outputFile
}
main