Sign in
|
Join PowerShell.com!
|
Help
Home
PowerTips
Ask the Experts
Forums
Webcasts
Blogs
eBook
Script Library
Twitter Grid
Modules
QuickClick
Scripts
Snippets
Videos
Library
»
Script Library
»
SQL Server
»
Get-MSSQL-ServerAttrib-Html
Get-MSSQL-ServerAttrib-Html
Share
|
Browse Library
Module Library
QuickClick Library
Script Library
Active Directory
BizTalk
Citrix
Clustering
Desktop
Exchange Server 2003
Exchange Server 2007
File System
Group Policy
Internet Information Server (IIS)
Local Accounts
Logs
Microsoft Office
Microsoft Team Foundation Server
MySQL
Networking
Registry
Remote Desktop Services
Remoting
Security
SharePoint
SQL Server
System Center Virtual Machine Manager
System Center Configuration Manager
System Center Operations Manager
Tutorial
Terminal Server
Using .Net
Virtual Server
VMware
Windows 7
Windows HPC
Windows Server 2000
Windows Server 2003
Windows Server 2008
Windows XP
WMI
Misc
Snippet Library
Video Library
Members Only
Tags
Access
ADO
Analysis Server
Attributes
Backup
CheckDB
Connect
Connection String
Create database
Create table
CSV
Database
DMO
Job
Port
Service
SMO
SQL
SQL Authentication
SQL Server
stop jobs
Views
Windows Authentication
Wizard
WMI
View more
Previous
|
Next
|
View all files
|
View Slideshow
Download
posted by
Richard Giles
10-06-2008
Downloads: 484
File size: 2.5kB
Views: 1,382
Embed
Get-MSSQL-ServerAttrib-Html
## =====================================================================
## 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:\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
Filed under:
SQL Server
,
SMO
,
Attributes
,
HTML
Connect to SQL Server and output server attributes to HTML
Copyright 2011 PowerShell.com. All rights reserved.