Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I was able to find pages explaining how Maintenance Plans write and how to query them. Between that and a discussion on how to use PowerShell to query XMLhow to use PowerShell to query XML, I think I have what I need to pull the maintenance plans in and query them. Since the SSIS package is essentially an XML document, I'm going to need to dust off (and tune up) my XQuery but here's what I have so far:

# TODO: Add a foreach statement, go through $ServerList, 
ouput to DBA database with date, server/instance info with $xmlDocs, 
turn below into a proper generic function

$MyQuery = "SELECT name
      ,CAST(CAST(packagedata as varbinary(max)) as xml) AS PackageSource
      ,packagetype
       ,id
      ,description
      ,createdate
  FROM msdb.dbo.sysssispackages WHERE [sysssispackages].[packagetype] = 6"
$server = '.'
$con = New-Object System.Data.SqlClient.SqlConnection
$con.ConnectionString = "Server=$server; Database=msdb;Integrated Security=true"
$con.open()

$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.CommandText = $MyQuery
$cmd.Connection = $con

$as = New-Object System.Data.SqlClient.SqlDataAdapter
$ds = New-Object System.Data.DataSet
$as.SelectCommand = $cmd
$as.Fill($ds);

$xmlDocs = $ds.Tables[0] | %{ $_.PackageSource }

I was able to find pages explaining how Maintenance Plans write and how to query them. Between that and a discussion on how to use PowerShell to query XML, I think I have what I need to pull the maintenance plans in and query them. Since the SSIS package is essentially an XML document, I'm going to need to dust off (and tune up) my XQuery but here's what I have so far:

# TODO: Add a foreach statement, go through $ServerList, 
ouput to DBA database with date, server/instance info with $xmlDocs, 
turn below into a proper generic function

$MyQuery = "SELECT name
      ,CAST(CAST(packagedata as varbinary(max)) as xml) AS PackageSource
      ,packagetype
       ,id
      ,description
      ,createdate
  FROM msdb.dbo.sysssispackages WHERE [sysssispackages].[packagetype] = 6"
$server = '.'
$con = New-Object System.Data.SqlClient.SqlConnection
$con.ConnectionString = "Server=$server; Database=msdb;Integrated Security=true"
$con.open()

$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.CommandText = $MyQuery
$cmd.Connection = $con

$as = New-Object System.Data.SqlClient.SqlDataAdapter
$ds = New-Object System.Data.DataSet
$as.SelectCommand = $cmd
$as.Fill($ds);

$xmlDocs = $ds.Tables[0] | %{ $_.PackageSource }

I was able to find pages explaining how Maintenance Plans write and how to query them. Between that and a discussion on how to use PowerShell to query XML, I think I have what I need to pull the maintenance plans in and query them. Since the SSIS package is essentially an XML document, I'm going to need to dust off (and tune up) my XQuery but here's what I have so far:

# TODO: Add a foreach statement, go through $ServerList, 
ouput to DBA database with date, server/instance info with $xmlDocs, 
turn below into a proper generic function

$MyQuery = "SELECT name
      ,CAST(CAST(packagedata as varbinary(max)) as xml) AS PackageSource
      ,packagetype
       ,id
      ,description
      ,createdate
  FROM msdb.dbo.sysssispackages WHERE [sysssispackages].[packagetype] = 6"
$server = '.'
$con = New-Object System.Data.SqlClient.SqlConnection
$con.ConnectionString = "Server=$server; Database=msdb;Integrated Security=true"
$con.open()

$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.CommandText = $MyQuery
$cmd.Connection = $con

$as = New-Object System.Data.SqlClient.SqlDataAdapter
$ds = New-Object System.Data.DataSet
$as.SelectCommand = $cmd
$as.Fill($ds);

$xmlDocs = $ds.Tables[0] | %{ $_.PackageSource }
Source Link
Elsimer
  • 375
  • 1
  • 4
  • 13

I was able to find pages explaining how Maintenance Plans write and how to query them. Between that and a discussion on how to use PowerShell to query XML, I think I have what I need to pull the maintenance plans in and query them. Since the SSIS package is essentially an XML document, I'm going to need to dust off (and tune up) my XQuery but here's what I have so far:

# TODO: Add a foreach statement, go through $ServerList, 
ouput to DBA database with date, server/instance info with $xmlDocs, 
turn below into a proper generic function

$MyQuery = "SELECT name
      ,CAST(CAST(packagedata as varbinary(max)) as xml) AS PackageSource
      ,packagetype
       ,id
      ,description
      ,createdate
  FROM msdb.dbo.sysssispackages WHERE [sysssispackages].[packagetype] = 6"
$server = '.'
$con = New-Object System.Data.SqlClient.SqlConnection
$con.ConnectionString = "Server=$server; Database=msdb;Integrated Security=true"
$con.open()

$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.CommandText = $MyQuery
$cmd.Connection = $con

$as = New-Object System.Data.SqlClient.SqlDataAdapter
$ds = New-Object System.Data.DataSet
$as.SelectCommand = $cmd
$as.Fill($ds);

$xmlDocs = $ds.Tables[0] | %{ $_.PackageSource }