Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Chad Miller

Chad Miller is a Senior Manager of Database Administration at Raymond James Financial. Chad has worked with Microsoft SQL Server since 1999 and has been automating administration tasks using Windows Powershell since 2007. Chad is the Project Coordinator/Developer of the Powershell-based Codeplex project SQL Server PowerShell Extensions (SQLPSX). Chad leads the Tampa Powershell User Group and is a frequent speaker at users groups, SQL Saturdays and Code Camps.

T-SQL Tuesday #005: SSIS Reporting

Automating SQL Server Integration Services (SSIS) administration through PowerShell is very different than writing scripts against the core database engine. Once you move outside the core database engine the .NET classes for working with SQL Server features like SQL Server Integration Services vary greatly in the way they are implemented. The core database engine has a very rich and well-laid out object model in SQL Server Management Objects or SMO. Although SSIS  does not  have as rich or as intuitive an object model as SMO, we can still accomplish many administration tasks using a namespace called Microsoft.SqlServer.Dts.Runtime Namespace (ManagedDts).

The CodePlex project, SQL Server PowerShell Extensions includes a PowerShell V2 module which uses ManagedDts for accomplishing many common tasks in deploying and administering SSIS. In the spirit of TSQL Tuesday #005 this is my contribution—reporting and changing SSIS configurations and Connections

The use of configurations in SSIS provides DBAs with a challenging twist in troubleshooting SSIS packages at 3 in the morning allows developers the flexibility to dynamically set connection strings at runtime. So, being able to report and change configurations and connection information via scripts is a useful task. The first thing we need to do after downloading and installing SQLPSX is to modify the SSIS.psm1 file to either work against 2005 or 2008. This is because unfortunately ManagedDts is not backwards compatible. In PowerShell the # symbol is a comment–comment/uncomment the line for 2005 or 2008 to suite your environment.

#add-type -AssemblyName "Microsoft.SqlServer.ManagedDTS, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
add-type -AssemblyName "Microsoft.SqlServer.ManagedDTS, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"

We can then import the module into our current PowerShell session:

import-module SSIS

In this example we are going to determine the configuration and connection settings for 24 SSIS packages stored on the file system:

$packages = dir "C:\Program Files\Microsoft SQL Server\100\DTS\Packages\*" | select -ExpandProperty Fullname | foreach {get-ispackage -path $_ }
$packages | foreach {$package = $_; $_.Configurations | Select @{n='Package';e={$Package.DisplayName}}, Name,ConfigurationString}
$packages | foreach {$package = $_; $_.Connections | Select @{n='Package';e={$Package.DisplayName}}, Name,ConnectionString}

 

This produces the following output:

ssisConfigurations

ssisConnections

To make things more interesting and illustrate that you can not only report but also change properties with ManagedDts/PowerShell we’ll change the connection string for the configuration SSISCONFIG as part of a copy process. We’ll also create new folder called sqlpsx on the root of the SQL Server SSIS package store:

new-isitem "\msdb" "sqlpsx" "Z002"
copy-isitemfiletosql -path "C:\Program Files\Microsoft SQL Server\100\DTS\Packages\*" -destination "msdb\sqlpsx" -destinationServer "Z002" -connectionInfo @{SSISCONFIG=".\SQLEXPRESS"}            

Packages stored on SQL Server can be worked with just as like SSIS packages stored on the file system. The following code returns the configuration and connection information of our newly copied SSIS packages:

$packages = get-isitem -path '\sqlpsx' -topLevelFolder 'msdb' -serverName "Z002\SQL2K8" | where {$_.Flags -eq 'Package'} | foreach {get-ispackage -path $_.literalPath -serverName $_.Servername}
$packages | foreach {$package = $_; $_.Configurations | Select @{n='Package';e={$Package.DisplayName}}, Name,ConfigurationString}
$packages | foreach {$package = $_; $_.Connections | Select @{n='Package';e={$Package.DisplayName}}, Name,ConnectionString}

A few notes:

  • PowerShell version 2 is required. The code will not work in sqlps or PowerShell V1. To obtain a V1 compatible script you can download version 1.61 of SQLPSX
  • The example use Z002 as the SSIS server—modify accordingly.
  • Unlike SQL Server Management Studio (SSMS), ManagedDts requires full instance name for some of the underlying method calls, hence Z002\SQL2K8 instead of just Z002.
  • Notice the topLevelFolder parameter, unlike SSMS, ManagedDts does not provide a property or method to determine the toplevelfolder setting. See this post for more information.
  • The PowerShell code in this blog post wraps lines, however the full sample script can be downloaded from here

Comments

Posted by Jason Brimhall on 13 April 2010

Nice Submission.  Thanks for sharing.

Posted by Anonymous on 13 April 2010

Pingback from  Auto restart for gmod dedicated server tutorial | Host Rage

Posted by Anonymous on 15 April 2010

Pingback from  SSIS Reporting - SQL Server Central Debt on Me

Posted by Anonymous on 17 April 2010

Pingback from  SSIS Reporting - SQL Server Central Report Me

Leave a Comment

Please register or log in to leave a comment.