Creating a SQL Server instance inventory
In this recipe, we will export SQL Server instance properties to a text file.
How to do it...
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Import the
SQLPS
module, and create a new SMO Server object as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking #replace this with your instance name $instanceName = "KERRIGAN" $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
Add the following script and run:
#specify folder and filename to be produced $folder = "C:\Temp" $currdate = Get-Date -Format "yyyy-MM-dd_hmmtt" $filename = "$($instanceName)_InstanceInventory_$($currdate).csv" $fullpath = Join-Path $folder $filename #export all “server” object properties #note we are using V3 simplified Where-Object syntax $server | Get-Member | Where-Object Name -ne "SystemMessages" | Where-Object MemberType -eq "Property" | Select...