Get-MSSQL-ServerAttrib-Html


posted by Richard Giles
10-06-2008

Downloads: 484
File size: 2.5kB
Views: 1,382

Embed
Get-MSSQL-ServerAttrib-Html
  1. ## ===================================================================== 
  2. ## Title       : Get-MSSQL-ServerAttrib-Html 
  3. ## Description : Connect to SQL Server and output server attributes to HTML 
  4. ## Author      : Idera 
  5. ## Date        : 9/1/2008 
  6. ## Input       : -serverInstance <server\instance> 
  7. ##                   -tempDir <file path> 
  8. ##                   -verbose  
  9. ##                   -debug     
  10. ## Output      :  
  11. ## Usage            : PS> . Get-MSSQL-ServerAttrib-Html -serverInstance MyServer  
  12. ##                             -tempDir C:\TEMP\ -v -d 
  13. ## Notes            : 
  14. ## Tag            : SQL Server, Attributes, HTML 
  15. ## Change log  : 
  16. ## ===================================================================== 
  17.  
  18. param 
  19.     [string]$serverInstance = "(local)"
  20.       [string]$tempDir = "C:\TEMP\"
  21.     [switch]$verbose
  22.     [switch]$debug 
  23.  
  24. function main() 
  25.     if ($verbose) {$VerbosePreference = "Continue"
  26.     if ($debug) {$DebugPreference = "Continue"
  27.     Get-MSSQL-ServerAttrib-Html $serverInstance $tempDir 
  28.  
  29. function Get-MSSQL-ServerAttrib-Html($serverInstance, $tempDir
  30.     $outputFile = $tempDir + "SQLServerAttributes.html" 
  31.     Write-Debug "Output directory: $outputFile" 
  32.      
  33.     # Validate path to temp directory 
  34.     if (-not (Test-Path -path $tempDir))  
  35.     
  36.         Write-Host Unable to validate path to temp directory: $tempDir 
  37.         break 
  38.     
  39.      
  40.     # Load-SMO assemblies 
  41.     [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo"
  42.     [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlEnum"
  43.     [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum")  
  44.     [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo")  
  45.      
  46.     # Create a Server object for default instance 
  47.     Write-Debug "Connecting to server: $ServerInstance"  
  48.     $namedInstance = New-Object ('Microsoft.SqlServer.Management.Smo.Server') ($serverInstance
  49.  
  50.     # Get server attributes and convert attribute info to HTML 
  51.     # Save to file and overwrite the file if it exists 
  52.      
  53.     Write-Debug "Saving $outputFile..." 
  54.     # TIP: using PowerShell convert an output stream to formatted HTML 
  55.     $namedInstance.EnumServerAttributes() | ` 
  56.         convertto-html -property attribute_name, attribute_value ` 
  57.         -title "Server Attributes" -body '<font face="Verdana">'
  58.         | foreach {$_ -replace "<th>", "<th align=left>"} ` 
  59.         | Out-File $outputFile 
  60.      
  61.     # TIP: Open new browser window and display ServerAttributes.html 
  62.     #      requires confirmation 
  63.     invoke-item $outputFile -confirm 
  64.  
  65.     # Cleanup 
  66.     remove-variable namedInstance  
  67.     remove-variable tempDir 
  68.     remove-variable outputFile 
  69.  
  70. main 
Filed under: , , ,

Connect to SQL Server and output server attributes to HTML

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.