On a current project I was working on, my task involved setting up a test environment which involved copying 60 SSIS packages from the production server to a test server. The problem at hand was the production server name was specified in the SSIS package connections and I did not want to go through each package manually and change the server name. Also, each package contained multiple connections including a connection to a DB2 production server. I'm a newbie to powershell and after reading many articles on the internet, I decided to automate the process using a powershell script.
PREREQUISITES
- Install Powershell v2.0 - http://www.simple-talk.com/sysadmin/powershell/powershell-version-2-what-is-new-and-why-is-it-important/
- Install SQLPSX - http://www.sql-server-performance.com/2011/powershell-sql-server-example/
THE POWERSHELL SCRIPT
The powershell script takes a number of parameters:
$sourceSQLServerName: Production SQL Server to get a copy of SSIS packages
$destinationSQLServerName: Test SQL Server to load modified SSIS packages
$MSDBFolderName: Folder name within MSDB where SSIS packages are stored
$oldSQLServerName: Old SQL Server name that will be replaced by new name in SSIS package connections
$newSQLServerName: New SQL Server name that will replace old name in SSIS package connections
$oldDB2ServerName: Old DB2 Server name that will be replaced by new name in SSIS package connections
$newDB2ServerName: New DB2 Server name that will replace old name in SSIS package connections
$oldFileConnectionPath: Old file path that will be replaced by new file path in SSIS package connections
$newFileConnectionPath: New file path that will replace old file path in SSIS package connections
After the script is run, you can double check the modified SSIS packages which are copied to the local file system to verify connections were updated correctly.
REFERENCES
http://www.simple-talk.com/sql/database-administration/im-a-sql-server-dba,-and-im-in-love-with-powershell/?utm_source=simpletalk&utm_medium=email-main&utm_content=PowershellLove-20100614&utm_campaign=SQL
http://www.simple-talk.com/sysadmin/powershell/powershell-version-2-what-is-new-and-why-is-it-important/
http://www.sql-server-performance.com/2011/powershell-sql-server-example/
http://www.sqlservercentral.com/articles/powershell/73288/
http://sqlblog.com/blogs/jamie_thomson/archive/2011/02/02/export-all-ssis-packages-from-msdb-using-powershell.aspx
http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/04/13/t_2D00_sql-tuesday-_2300_005_3A00_-ssis-reporting.aspx
http://blogs.technet.com/b/smsandmom/archive/2008/06/04/windows-powershell-basics-part-2.aspx
http://widba.blogspot.com/2011/04/ssis-package-versions-with-powershell.html
http://www.timvw.be/2011/03/12/some-powershell-functions-to-work-with-ssis-packages/
http://www.timvw.be/2010/11/11/update-configurationstrings-in-ssis-package-with-powershell/
http://billfellows.blogspot.com/2010/05/powershell-dtutil-ssisdeploymanifest.html
http://msdn.microsoft.com/en-us/library/cc281954.aspx
http://www.computerperformance.co.uk/powershell/powershell_variables.htm
http://www.w3schools.com/xpath/xpath_syntax.asp
http://www.sqlservercentral.com/articles/powershell/72051/