<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'powershell', 'sql server integration services', and 'ssis'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=powershell,sql+server+integration+services,ssis&amp;orTags=0</link><description>Search results matching tags 'powershell', 'sql server integration services', and 'ssis'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Export all SSIS packages from msdb using Powershell</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2011/02/02/export-all-ssis-packages-from-msdb-using-powershell.aspx</link><pubDate>Wed, 02 Feb 2011 07:45:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:33124</guid><dc:creator>jamiet</dc:creator><description>&lt;P&gt;Have you ever wanted to dump all the SSIS packages stored in msdb out to files? Of course you have, who wouldn’t? Right? Well, at least one person does because this was the subject of a thread (&lt;A href="http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/thread/cd5f9ed6-8dd2-4ba7-9acd-b6ce2c04b7a1" target=_blank&gt;save all ssis packages to file&lt;/A&gt;) on the &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/threads" target=_blank&gt;SSIS forum&lt;/A&gt; earlier today.&lt;/P&gt;
&lt;P&gt;Some of you may have already figured out a way of doing this but for those that haven’t here is a nifty little script that will do it for you and it uses our favourite jack-of-all tools … Powershell!!&lt;/P&gt;
&lt;P&gt;Imagine I have the following package folder structure on my Integration Services server (i.e. in [msdb]):&lt;/P&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/image_2014D2B2.png"&gt;&lt;IMG style="BACKGROUND-IMAGE:none;BORDER-RIGHT-WIDTH:0px;MARGIN:;PADDING-LEFT:0px;PADDING-RIGHT:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;PADDING-TOP:0px;" title=image border=0 alt=image src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_2BCA19E4.png" width=442 height=239&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;There are two packages in there called “20110111 Chaining Expression components” &amp;amp; “Package”, I want to export those two packages into a folder structure that mirrors that in [msdb]. Here is the Powershell script that will do that:&lt;/P&gt;&lt;PRE&gt;&lt;FONT size=1&gt;&lt;SPAN style="COLOR:#0000ff;"&gt;Param&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$SQLInstance&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#ff0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;localhost&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;"&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;SPAN style="COLOR:#000000;"&gt;)

&lt;/SPAN&gt;&lt;SPAN style="COLOR:#008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="COLOR:#008000;"&gt;####Add all the SQL goodies (including Invoke-Sqlcmd)#####&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="COLOR:#008000;"&gt;
&lt;/SPAN&gt;&lt;FONT size=1&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;add-pssnapin&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;sqlserverprovidersnapin100&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-ErrorAction&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;SilentlyContinue&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="COLOR:#000000;"&gt;
&lt;/SPAN&gt;&lt;FONT size=1&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;add-pssnapin&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;sqlservercmdletsnapin100&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-ErrorAction&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;SilentlyContinue&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="COLOR:#000000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;&lt;FONT size=1&gt;cls&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=1&gt;&lt;SPAN style="COLOR:#000000;"&gt; 

&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$Packages&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#ff0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;  &lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;Invoke-Sqlcmd&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-MaxCharLength&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;10000000&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-ServerInstance&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$SQLInstance&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-Query&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;"&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;SPAN style="COLOR:#800000;"&gt;WITH cte AS (
                                                                        SELECT    cast(foldername as varchar(max)) as folderpath, folderid
                                                                        FROM    msdb..sysssispackagefolders
                                                                        WHERE    parentfolderid = '00000000-0000-0000-0000-000000000000'
                                                                        UNION    ALL
                                                                        SELECT    cast(c.folderpath + '\' + f.foldername  as varchar(max)), f.folderid
                                                                        FROM    msdb..sysssispackagefolders f
                                                                        INNER    JOIN cte c        ON    c.folderid = f.parentfolderid
                                                                    )
                                                                    SELECT    c.folderpath,p.name,CAST(CAST(packagedata AS VARBINARY(MAX)) AS VARCHAR(MAX)) as pkg
                                                                    FROM    cte c
                                                                    INNER    JOIN msdb..sysssispackages p    ON    c.folderid = p.folderid
                                                                    WHERE    c.folderpath NOT LIKE 'Data Collector%'&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;"&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="COLOR:#000000;"&gt;

&lt;/SPAN&gt;&lt;FONT size=1&gt;&lt;SPAN style="COLOR:#0000ff;"&gt;Foreach&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$pkg&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#0000ff;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$Packages&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;SPAN style="COLOR:#000000;"&gt;)
{
    &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$pkgName&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#ff0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$Pkg&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="COLOR:#8b4513;"&gt;name&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="COLOR:#000000;"&gt;
&lt;FONT size=1&gt;    &lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=1&gt;&lt;SPAN style="COLOR:#800080;"&gt;$folderPath&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#ff0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$Pkg&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="COLOR:#8b4513;"&gt;folderpath&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="COLOR:#000000;"&gt;
&lt;FONT size=1&gt;    &lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=1&gt;&lt;SPAN style="COLOR:#800080;"&gt;$fullfolderPath&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#ff0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;c:\temp\$folderPath\&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;"&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="COLOR:#000000;"&gt;
&lt;FONT size=1&gt;    &lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=1&gt;&lt;SPAN style="COLOR:#0000ff;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:#ff0000;"&gt;!&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;test-path&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-path&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$fullfolderPath&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;SPAN style="COLOR:#000000;"&gt;))
    {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;"&gt;mkdir&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$fullfolderPath&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; | &lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;Out-Null&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="COLOR:#000000;"&gt;
&lt;FONT size=1&gt;    }
    &lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size=1&gt;&lt;SPAN style="COLOR:#800080;"&gt;$pkg&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="COLOR:#8b4513;"&gt;pkg&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; | &lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;Out-File&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-Force&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-encoding&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;ascii&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-FilePath&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;$fullfolderPath\$pkgName.dtsx&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;"&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="COLOR:#000000;"&gt;
&lt;FONT size=1&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;To run it simply change the “localhost” parameter of the server you want to connect to either by editing the script or passing it in when the script is executed. It will create the folder structure in C:\Temp (which you can also easily change if you so wish – just edit the script accordingly). Here’s the folder structure that it created for me:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/image_7578F1D4.png"&gt;&lt;IMG style="BACKGROUND-IMAGE:none;BORDER-RIGHT-WIDTH:0px;MARGIN:;PADDING-LEFT:0px;PADDING-RIGHT:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;PADDING-TOP:0px;" title=image border=0 alt=image src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_33FE3F7B.png" width=537 height=222&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Notice how it is a mirror of the folder structure in [msdb].&lt;/P&gt;
&lt;P&gt;Hope this is useful!&lt;/P&gt;
&lt;P&gt;&lt;A href="http://twitter.com/jamiet"&gt;@Jamiet&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;UPDATE: THis post prompted Chad Miller to write a post describing his Powershell add-in that utilises a SSIS API to do exporting of packages. Go take a read here: &lt;A href="http://sev17.com/2011/02/importing-and-exporting-ssis-packages-using-powershell/"&gt;http://sev17.com/2011/02/importing-and-exporting-ssis-packages-using-powershell/&lt;/A&gt;&lt;/P&gt;</description></item></channel></rss>