Creating a SQL Server instance inventory
In this recipe, we will export SQL Server instance properties to a text file.
How to do it...
Let's see how to create a SQL Server instance inventory file:
- Open PowerShell ISE as administrator.
- Import the SQLPS module and create a new SMO Server Object:
#import SQL Server module Import-Module SQLPS -DisableNameChecking #replace this with your instance name $instanceName = "localhost" $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)_$($currdate).csv" $fullpath = Join-Path $folder $filename #export all "server" object properties $server | Get-Member | Where-Object Name -ne "SystemMessages" | Where-Object MemberType -eq "Property" | Select-Object Name, @{Name...