Skip to main content

Posts

Showing posts from July, 2011

How cluttered is MSDB?

# My quick and dirty PowerShell script to check for the oldest entry in MSDB. # I'm using a SQLPSX 1.6 function Get-SqlData to execute queries. # Runs against multiple servers 1: $start = get-date 2: write-host "Start: " $start 3:   4: $serverName = "SERVER\INSTANCE" 5: $databaseName = "dbINVENTORY" 6:   7: $FilePath = "C:\Output" 8: $OutFile = Join-Path -path $FilePath -childPath ( "MSDB_MIN_Date_" + (get-date).toString( 'yyyyMMdd_hhmmtt' ) + ".csv" ) 9:   10: # here string contains SQL query 11: $qry = @" 12: SELECT DISTINCT 13: ISNULL(A.MACH_LPAR_NM, '') + CASE INST_NM 14: WHEN 'DEFAULT' THEN '' 15: ELSE '\' 16: END + CASE INST_NM 17: WHEN 'DE