Sign in
|
Join PowerShell.com!
|
Help
Home
PowerTips
Ask the Experts
Forums
Webcasts
Blogs
eBookV2
Script Library
Twitter Grid
Modules
QuickClick
Scripts
Snippets
Videos
Library
»
Script Library
»
SQL Server
»
Get-MSSQL-ServerAttrib-Csv
Get-MSSQL-ServerAttrib-Csv
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
AD
ADO
Analysis Server
Attributes
Backup
CheckDB
Connect
Connection String
Create database
Create table
CSV
Database
Port
PowerShell
Properties
Service
SMO
SQL
SQL Authentication
SQL Server
stop jobs
test-connection
Windows Authentication
WMI
View more
Previous
|
Next
|
View all files
|
View Slideshow
Download
posted by
Richard Giles
10-06-2008
Downloads: 496
File size: 2.4kB
Views: 1,265
Embed
Get-MSSQL-ServerAttrib-Csv
## =====================================================================
## Title
: Get-MSSQL-ServerAttrib-Csv
## Description : Connect to SQL Server and output server attributes to CSV
## Author
: Idera
## Date
: 9/1/2008
## Input
: -serverInstance <server\instance>
##
-tempDir <output path>
##
-verbose
##
-debug
## Output
: CSV file with server attributes
## Usage
: PS> . Get-MSSQL-ServerAttrib-Csv -serverInstance MyServer
##
-tempDir C:\TEMP\ -v -d
## Notes
:
## Tag
: SQL Server, Attributes, CSV
## 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-Csv
$serverInstance
$tempDir
}
function
Get-MSSQL
-
ServerAttrib-Csv
(
$serverInstance
,
$tempDir
)
{
trap
[
Exception
]
{
write-error
$
(
"TRAPPED: "
+
$_
.
Exception.Message
);
continue
;
}
# Create fully qualified output filename
$outputFile
=
$tempDir
+
"SQLServerAttributes.csv"
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 with EnumServerAttributes() method and output to CSV
#
and overwrite existing file
Write-Debug
"Outputing $outputFile..."
$NamedInstance
.
EnumServerAttributes
() |
Export-Csv
-path
$outputFile
# Cleanup
# TIP: variables will go out of scope when the function ends
#
this is a why to specifically dispose them
remove-variable
NamedInstance
remove-variable
TempDir
remove-variable
OutputFile
}
main
Filed under:
SQL Server
,
SMO
,
Attributes
Connect to SQL Server and output server attributes to CSV.
Copyright 2011 PowerShell.com. All rights reserved.