Skip to content

shannonlowder.com

Menu
  • About
  • Biml Interrogator Demo
  • Latest Posts
Menu

PowerShell Management for Your SSIS Packages

Posted on December 10, 2013May 23, 2017 by slowder

In addition to working on my database sharding presentation I’ve been working on upgrading an ETL framework.  In learning this new framework I dug into the business logic as to what the framework was trying to load, looked into all the auditing that was currently captured, and I looked for gaps when packages didn’t perform as expected.  It took a few weeks to dig through the full project, and now that I’m starting to make incremental improvements to this process, I’m finding PowerShell can be a powerful tool in your SSIS tool belt.  The trick is, you have to sharpen that tool before you can really use it.

SQLPSX

SSIS Packages are just XML right?  So you can just parse out the XML and interact that way, right?

You could.  It would take a lot of time and energy, but you could.  I’m fortunate to have stumbled across SQLPSX, SQL Server PowerShell Extensions on codeplex.  With this, I was able to really dig into my packages and manage my variables (both at the package and container level), connection strings, executables, and more!  All of that without once having to build out a XMLPath statement or build out a complex TRY..CATCH to see if the package put the variable in the root node, or in one of the children nodes of the current element.

This tool hasn’t been touched since March 2011, but it’s served as the base for several tools I built over the past week.  Download it, and PowerGUI, my current PowerShell IDE.  (If you know a better IDE for PowerShell, hit me up in the comments!)  Then get started with a couple of these demos.

What packages have this variable?

In this framework we moved from building MERGE statements through expressions, to building them via a stored procedure.  The problem is we have nearly a hundred packages I have to go check to find out which ones were already upgraded, and which ones haven’t yet been upgraded.

How much time would that take to open each package in your project, look for the variables and build a to-do list?

Too much.

Let’s do it the easy way:

update: I’ve added the management scripts to a GitHub repository, and you can find the reading variables script here!

Import-Module -Name c:\code\posh\SQLPSX-Modules\SSIS
$path = "C:\code\localrepolocation"
$loadPackages = Get-ChildItem -path $path -Filter "*_load.dtsx"
foreach($loadPackage in  $loadPackages) {
     $packagePath = $path + "\" + $loadPackage
     $package = Get-ISPackage -path $packagePath
     foreach($variable in $package.Variables) {
          if ($variable.Name -eq "VariableName") {
	       $package.Name + " has VariableName, with value: " + $variable.Value
	  }
     }
}

Ok, let’s start at the top.  The first line gives me access to the SSIS POSH modules.  Since I will be deploying this to other machines, I will have to make sure I deploy both this script, and the SSIS module to the same folder structure as I use in dev.  If I don’t then I would need to update my package to new paths.

Next, I set a variable for the path where I’ve stored my packages.  This is the working clone of the ETL repository.

Then, I spin through and grab all the packages in that folder that end with _load.dtsx.  The up-side to having a naming convention is I can spin through my packages and trust that I’m grabbing only the load packages, and not my stage, transform, or transfer packages.  The -Filter option can work wonders with the Get-ChildItem commandlet.

Once I’ve loaded all my packages into the $loadPackages object, in this case I think it’s a collection).  I use a foreach to deal with each package one at a time.

CaptureI build out a fully qualified name and path for each package, which I need to pass on to the Get-ISPackage commandlet from SQLPSX.  This is the real engine in this tool.  It grabs your package, and then loads it into an object that IS your package!

Once you have this object, you can do nearly anything you could do through BIDS/SSDT.  Check out the screen shot, then try it for yourself.  Explore the object, see what all you have access to. It will blow you away once you see it all laid out right in front of you!

Now, back to the script.  The next foreach loop spins through all our package variables, and checks their names.  If we find the one named “VariableName”, then we output “That package has VariableName, with value: blah”.  That output becomes your to-do list.  You can then go and perform the work of upgrading just those packages that need to be upgraded, without having to open those that don’t have any work to-do!

Think about the possibilities of looking at all of your packages, and seeing all the variables you are using.  You could create a CSV of all the package names and variable names.  You could then drop that into a database, and build a query that would show you which packages aren’t using your standard variable names.  You could also check for variables with the wrong default values.  The key is this: anything you can do through the GUI, you could now do through PowerShell.  That means it’s automatable, repeatable, and reduces the chance for human failure.

In a future article, I want to share with you how I built a testing framework that spins through just the files I have modified and not checked in to source control, executes them, checks to see if they succeed or not.  If they succeed, then it goes to compare the results in the database versus the last production run, if the results are the same, then the output is validated.  I could then build on top of that to make that a requirement before checking my new or updated packages into the repository!  This is test-based development for SSIS folks!

This is exciting stuff folks!

As always, if you have any questions, please send them in.  I’m here to help!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • A New File Interrogator
  • Using Generative AI in Data Engineering
  • Getting started with Microsoft Fabric
  • Docker-based Spark
  • Network Infrastructure Updates

Recent Comments

  1. slowder on Data Engineering for Databricks
  2. Alex Ott on Data Engineering for Databricks

Archives

  • July 2023
  • June 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • October 2018
  • August 2018
  • May 2018
  • February 2018
  • January 2018
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • June 2017
  • March 2017
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • August 2013
  • July 2013
  • June 2013
  • February 2013
  • January 2013
  • August 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • November 2004
  • September 2004
  • August 2004
  • July 2004
  • April 2004
  • March 2004
  • June 2002

Categories

  • Career Development
  • Data Engineering
  • Data Science
  • Infrastructure
  • Microsoft SQL
  • Modern Data Estate
  • Personal
  • Random Technology
  • uncategorized
© 2025 shannonlowder.com | Powered by Minimalist Blog WordPress Theme