<?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>SSIS Junkie : Powershell</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/tags/Powershell/default.aspx</link><description>Tags: Powershell</description><dc:language>en</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><slash:comments>8</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/33124.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=33124</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=33124</wfw:comment><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;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=33124" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sql+server/default.aspx">sql server</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sql+server+integration+services/default.aspx">sql server integration services</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/ssis/default.aspx">ssis</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Powershell/default.aspx">Powershell</category></item><item><title>Generate multiple SqlCmdVars files in your database projects</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2011/01/19/generate-multiple-sqlcmdvars-vars-in-your-database-projects.aspx</link><pubDate>Wed, 19 Jan 2011 20:24:59 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:32757</guid><dc:creator>jamiet</dc:creator><slash:comments>5</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/32757.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=32757</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=32757</wfw:comment><description>&lt;p&gt;Earlier today I was doing a little work using datadude/DBPro/Visual Studio Database Tools/pick your name and had a need to write a Powershell script that I think might be useful to other folks so I’m sharing it here.&lt;/p&gt;  &lt;p&gt;Often when you’re putting together database projects you will have a need for multiple .sqlcmdvars files – one for each environment that you are deploying to. It can be a real pain in the neck maintaining multiple .sqlcmdvars files because you need to make sure that:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;each file has the same list of sqlcmd variables in it &lt;/li&gt;    &lt;li&gt;the variables that need to be different per environment have got the correct values in them &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If you have multiple environments and multiple projects then this can become a real headache to maintain – indeed, the project that I am working on at the moment has got 192 sqlcmdvars files. You can trust me that that is pretty excessive however this problem is still one that many people are going to encounter.&lt;/p&gt;  &lt;p&gt;So, when you have 192 occurences of the same problem it seems logical to write a script to carry out the repetitive task of editing those files and that is exactly what I did today. My Powershell script requires that you maintain ONE .sqlcmdvars file per project and will then take care of generating the others and also replacing environment-specific variable values where appropriate. You need to supply a list of a projects, a list of environments and, for each environment, a value for each variable that you want to change. the example below has only one project, three environments (thus three .sqlcmdvars files) and one environment-specific variable. If you have anything more complex than that then the script is very easy to change and is self-explanatory.&lt;/p&gt;  &lt;p&gt;Here’s a screenshot of my demo project:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_2F9C93E4.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_438600AD.png" width="767" height="465" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Note the following:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;There are three sqlcmdvars files {development.sqlcmdvars,production.sqlcmdvars,test.sqlcmdvars} &lt;/li&gt;    &lt;li&gt;development.sqlcmdvars contains a variable called $(EmailAddress) that is not in either of the other two &lt;/li&gt;    &lt;li&gt;My Powershell script is stored as a solution file &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here is the script:&lt;/p&gt;  &lt;pre&gt;&lt;font size="2"&gt;&lt;span style="color:#008000;"&gt;#&lt;/span&gt;&lt;span style="color:#008000;"&gt;This script copies the contents of each &amp;lt;defined&amp;gt;.sqlcmdvars into all the other .sqlcmdvars files for that project&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;font size="2"&gt;#&lt;/font&gt;&lt;/span&gt;&lt;span style="color:#008000;"&gt;&lt;font size="2"&gt;It should live in the root folder of your solution&lt;br /&gt;#If your sqlcmdvars files are under source control don’t forget to check them out&lt;/font&gt;&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#5f9ea0;font-weight:bold;"&gt;&lt;font size="2"&gt;cls&lt;/font&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$masterSqlCmdVars&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;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;development&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&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;Edit these two&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$variableName&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;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;EmailAddress&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&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;values accordingly&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$DbArray&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;20110119 Test Sqlcmdvars Generator&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&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;List all your .dbproj files&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&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;$Db&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;$DbArray&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&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;List of environments and the property values for each respective environment&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;    &lt;/span&gt;&lt;span style="color:#800080;"&gt;$EnvArray&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&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;test&lt;/span&gt;&lt;span style="color:#800000;"&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;test@example.com&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&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;production&lt;/span&gt;&lt;span style="color:#800000;"&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;production@example.com&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
                )
    &lt;/span&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;$Env&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;$EnvArray&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&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;STEP 1 - copy the file&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$EnvName&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;$Env&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;[0]
        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$VarValue&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;$Env&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;[1]
        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$source&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;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;$Db\Properties\$masterSqlCmdVars.sqlcmdvars&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$destination&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;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;$Db\Properties\$EnvName.sqlcmdvars&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Copying $source to $destination&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#5f9ea0;font-weight:bold;"&gt;copy&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$source&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;

&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#008000;"&gt;#&lt;/span&gt;&lt;span style="color:#008000;"&gt;STEP 2 - edit with new variable values&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$xml&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:#008080;"&gt;xml&lt;/span&gt;&lt;span style="color:#000000;"&gt;](&lt;/span&gt;&lt;span style="color:#5f9ea0;font-weight:bold;"&gt;Get-Content&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$root&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;$xml&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;get_DocumentElement&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;();
        &lt;/span&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;$property&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;$root&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;Properties&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;ChildNodes&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
        {
            &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;if&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#800080;"&gt;$property&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;PropertyName&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;-eq&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$variableName&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
            {
                &lt;/span&gt;&lt;span style="color:#800080;"&gt;$property&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;Propertyvalue&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;$VarValue&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;            }
        }
        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Saving modified XML to $destination&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$destination&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;resolve-path&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$xml&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;Save&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;&lt;font size="2"&gt;)
    }
}&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;It has an outer loop for all the projects and an inner loop for each environment. On each iteration it copies the contents of development.sqlcmdvars into $EnvName.sqlcmdvars and then updates the file with the new value for $(EmailAddress). If you have more variables that you need to edit then its not a great hardship to adapt the script accordingly.&lt;/p&gt;

&lt;p&gt;Upon completion our test.sqlcmdvars and production.sqlcmdvars files have been edited as so:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_11CAE358.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_2DABF283.png" width="765" height="470" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s it. Pretty simple. I won’t go deep into explaining the script because if this is useful to you you will probably want to do that yourself. This demo project, including the Powershell script, is available for download at &lt;a title="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110119/20110119%20Test%20Sqlcmdvars%20Generator.zip" href="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110119/20110119%20Test%20Sqlcmdvars%20Generator.zip"&gt;http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110119/20110119%20Test%20Sqlcmdvars%20Generator.zip&lt;/a&gt;.&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: I have discovered an alternative method &lt;a href="http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/e3281376-0e18-4494-afbe-a523b0fd1995/" target="_blank"&gt;courtesy of Robert Robelo&lt;/a&gt; and I like this one because it uses XPath which to me feels like a purer way of doing this – I can’t explain why so don’t ask! Here’s is Robert’s code which achieves the same as above:&lt;/p&gt;

&lt;pre&gt;&lt;span style="color:#5f9ea0;font-weight:bold;"&gt;&lt;font size="2"&gt;cls&lt;/font&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$masterSqlCmdVars&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;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;development&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&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;Edit these two&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$variableName&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;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;EmailAddress&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&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;values accordingly&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$DbArray&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;20110119 Test Sqlcmdvars Generator&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&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;List all your .dbproj files&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&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;$Db&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;$DbArray&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&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;List of environments and the property values for each respective environment&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;    &lt;/span&gt;&lt;span style="color:#800080;"&gt;$EnvArray&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;=&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&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;test&lt;/span&gt;&lt;span style="color:#800000;"&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;test@example.com&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&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;production&lt;/span&gt;&lt;span style="color:#800000;"&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;production@example.com&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
                )
    &lt;/span&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;$Env&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;$EnvArray&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&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;STEP 1 - copy the file&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$EnvName&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;$Env&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;[0]
        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$VarValue&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;$Env&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;[1]
        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$source&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;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;$Db\Properties\$masterSqlCmdVars.sqlcmdvars&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$destination&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;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;$Db\Properties\$EnvName.sqlcmdvars&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Copying $source to $destination&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#5f9ea0;font-weight:bold;"&gt;copy&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$source&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        
        [&lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#008080;"&gt;xml&lt;/span&gt;&lt;span style="color:#000000;"&gt;]&lt;/span&gt;&lt;span style="color:#800080;"&gt;$xml&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;Get-Content&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$nsMgr&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;New-Object&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;Xml.XmlNamespaceManager&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$xml&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;NameTable&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$prefix&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;ns&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$uri&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;urn:Microsoft.VisualStudio.Data.Schema.Package.SqlCmdVars&lt;/span&gt;&lt;span style="color:#800000;"&gt;'&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$nsMgr&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;AddNamespace&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#800080;"&gt;$prefix&lt;/span&gt;&lt;span style="color:#000000;"&gt;, &lt;/span&gt;&lt;span style="color:#800080;"&gt;$uri&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$xpath&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;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;//${prefix}:Property[./${prefix}:PropertyName='$variableName']&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$node&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;$xml&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;SelectSingleNode&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#800080;"&gt;$xpath&lt;/span&gt;&lt;span style="color:#000000;"&gt;, &lt;/span&gt;&lt;span style="color:#800080;"&gt;$nsMgr&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
        &lt;/span&gt;&lt;span style="color:#800080;"&gt;$node&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;PropertyValue&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;$VarValue&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;        &lt;/font&gt;&lt;/span&gt;&lt;font size="2"&gt;&lt;span style="color:#800080;"&gt;$xml&lt;/span&gt;&lt;span style="color:#000000;"&gt;.&lt;/span&gt;&lt;span style="color:#8b4513;"&gt;Save&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="color:#000000;"&gt;)
        &lt;/span&gt;&lt;span style="color:#5f9ea0;font-weight:bold;"&gt;Get-Content&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;$destination&lt;/span&gt;&lt;/font&gt;&lt;span style="color:#000000;"&gt;
&lt;font size="2"&gt;    }
}&lt;/font&gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;I have also updated the downloadable file at &lt;a title="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110119/20110119%20Test%20Sqlcmdvars%20Generator.zip" href="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110119/20110119%20Test%20Sqlcmdvars%20Generator.zip"&gt;http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20110119/20110119%20Test%20Sqlcmdvars%20Generator.zip&lt;/a&gt; with Robert’s code.&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=32757" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sql+server/default.aspx">sql server</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Powershell/default.aspx">Powershell</category></item><item><title>Querying Visual Studio project files using T-SQL and Powershell</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2011/01/17/querying-visual-studio-project-files.aspx</link><pubDate>Mon, 17 Jan 2011 21:11:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:32686</guid><dc:creator>jamiet</dc:creator><slash:comments>3</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/32686.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=32686</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=32686</wfw:comment><description>&lt;P&gt;Earlier today I had a need to get some information out of a Visual Studio project file and in this blog post I’m going to share a couple of ways of going about that because I’m pretty sure I won’t be the only person that ever wants to do this. The specific problem I was trying to solve was finding out how many objects in my database project (i.e. in my .dbproj file) had any warnings suppressed but the techniques discussed below will work pretty well for any Visual Studio project file because every such file is simply an XML document, hence it can be queried by anything that can query XML documents.&lt;/P&gt;
&lt;P&gt;Ever heard the phrase “when all you’ve got is hammer everything looks like a nail”? Well that’s me with querying stuff – if I can write SQL then I’m writing SQL. Here’s a little noddy database project I put together for demo purposes:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/image_003D882B.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_7E208961.png" width=211 height=244&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Two views and a stored procedure, nothing fancy. I suppressed warnings for [View1] &amp;amp; [Procedure1] and hence the pertinent part my project file looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;ItemGroup&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;Build&lt;/FONT&gt;&amp;nbsp;&lt;FONT color=#ff0000&gt;Include&lt;/FONT&gt;=&lt;FONT color=#000000&gt;"&lt;/FONT&gt;Schema Objects\Schemas\dbo\Views\View1.view.sql&lt;FONT color=#000000&gt;"&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;SubType&lt;/FONT&gt;&amp;gt;&lt;FONT color=#000000&gt;Code&lt;/FONT&gt;&amp;lt;/&lt;FONT color=#c0504d&gt;SubType&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT size=3&gt;&amp;lt;&lt;FONT color=#c0504d&gt;SuppressWarnings&lt;/FONT&gt;&amp;gt;&lt;FONT color=#000000&gt;4151,3276&lt;/FONT&gt;&amp;lt;/&lt;FONT color=#c0504d&gt;SuppressWarnings&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;FONT color=#c0504d&gt;Build&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;Build&lt;/FONT&gt; &lt;FONT color=#ff0000&gt;Include&lt;/FONT&gt;=&lt;FONT color=#000000&gt;"&lt;/FONT&gt;Schema Objects\Schemas\dbo\Views\View2.view.sql&lt;FONT color=#000000&gt;"&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;SubType&lt;/FONT&gt;&amp;gt;&lt;FONT color=#000000&gt;Code&lt;/FONT&gt;&amp;lt;/&lt;FONT color=#c0504d&gt;SubType&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;FONT color=#c0504d&gt;Build&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;Build&lt;/FONT&gt; &lt;FONT color=#ff0000&gt;Include&lt;/FONT&gt;=&lt;FONT color=#000000&gt;"&lt;/FONT&gt;Schema Objects\Schemas\dbo\Programmability\Stored Procedures\Procedure1.proc.sql&lt;FONT color=#000000&gt;"&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;SubType&lt;/FONT&gt;&amp;gt;&lt;FONT color=#000000&gt;Code&lt;/FONT&gt;&amp;lt;/&lt;FONT color=#c0504d&gt;SubType&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT size=3&gt;&amp;lt;&lt;FONT color=#c0504d&gt;SuppressWarnings&lt;/FONT&gt;&amp;gt;&lt;FONT color=#000000&gt;4151&lt;/FONT&gt;&amp;lt;/&lt;FONT color=#c0504d&gt;SuppressWarnings&lt;/FONT&gt;&amp;gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;FONT color=#c0504d&gt;Build&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/&lt;FONT color=#c0504d&gt;ItemGroup&lt;/FONT&gt;&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;&lt;FONT color=#c0504d&gt;ItemGroup&lt;/FONT&gt;&amp;gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Note the &lt;STRONG&gt;&amp;lt;&lt;FONT color=#c0504d&gt;SuppressWarnings&lt;/FONT&gt;&amp;gt; &lt;/STRONG&gt;elements – those are the bits of information that I am after.&lt;/P&gt;
&lt;P&gt;With &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/sqlxml/thread/2337b9bf-e123-4004-8af3-06d2b851c7e1/" target=_blank&gt;a lot of help&lt;/A&gt; from folks on the &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/sqlxml/threads" target=_blank&gt;SQL Server XML forum&lt;/A&gt;&amp;nbsp; I came up with the following query that nailed what I was after. It reads the contents of the .dbproj file into a variable of type XML and then shreds it using T-SQL’s &lt;A href="http://msdn.microsoft.com/en-us/library/ms190798.aspx" target=_blank&gt;XML data type methods&lt;/A&gt;: &lt;/P&gt;
&lt;TABLE cellSpacing=0 cellPadding=2&gt;

&lt;TR&gt;
&lt;TD&gt;&lt;CODE style="FONT-SIZE:12px;"&gt;&lt;SPAN style="COLOR:blue;"&gt;DECLARE &lt;/SPAN&gt;&lt;SPAN style="COLOR:#434343;"&gt;@xml &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;XML&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT &lt;/SPAN&gt;&lt;SPAN style="COLOR:#434343;"&gt;@xml &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;= &lt;/SPAN&gt;&lt;SPAN style="COLOR:magenta;"&gt;CAST&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;pkgblob.BulkColumn &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS XML&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&amp;nbsp;&amp;nbsp; OPENROWSET&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;BULK &lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'C:\temp\QueryingProjectFileDemo\QueryingProjectFileDemo.dbproj' &lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;-- &amp;lt;-Change this path! &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;single_blob&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;pkgblob &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WITH &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;XMLNAMESPACES&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;( &lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'http://schemas.microsoft.com/developer/msbuild/2003' &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;ns&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:magenta;"&gt;REVERSE&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:magenta;"&gt;SUBSTRING&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:magenta;"&gt;REVERSE&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;ObjectPath&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;),&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;0&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;CHARINDEX&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'\'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:magenta;"&gt;REVERSE&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;ObjectPath&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;)))) &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;[ObjectName] &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;[SuppressedWarnings] &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;( &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;build.query&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'.'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;[_node] &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;build.value&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'ns:SuppressWarnings[1]'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'nvarchar(100)'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;[SuppressedWarnings] &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;build.value&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'@Include'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'nvarchar(1000)'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;[ObjectPath] &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#434343;"&gt;@xml&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;.nodes&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'//ns:Build[ns:SuppressWarnings]'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS &lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;R&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;build&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;q &lt;BR&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;
&lt;P&gt;And here’s the output:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/image_4E826AD5.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_7B9757A3.png" width=533 height=164&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And that’s it – an easy way of discovering which warnings have been suppressed and for which objects in your database projects. I won’t bother going over the code as it is fairly self-explanatory – peruse it at your leisure.&lt;/P&gt;
&lt;P&gt;Once I had the SQL above I figured I’d share it around a little in case it was ever useful to anyone else; hence I’m writing this blog post and I also posted it on the &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/vstsdb/threads" target=_blank&gt;Visual Studio Database Development Tools forum&lt;/A&gt; at &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/8eacbe76-c6d1-40e2-af15-044903a98c1d/?prof=required" target=_blank&gt;FYI: Discover which objects have had warnings suppressed&lt;/A&gt;. Luckily &lt;A href="http://social.msdn.microsoft.com/profile/kevin%20goode/?type=forum&amp;amp;referrer=http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/8eacbe76-c6d1-40e2-af15-044903a98c1d/?prof=required" target=_blank&gt;Kevin Goode&lt;/A&gt; saw the thread and he posted a different solution to the same problem, one that uses Powershell. The advantage of Kevin’s Powershell approach is that it is easy to analyse many .dbproj files at the same time. Below is Kevin’s code which I have tweaked &lt;EM&gt;ever so slightly&lt;/EM&gt; so that it produces the same results as my SQL script (I just want any object that had had a warning suppressed whereas Kevin was querying specifically for warning 4151):&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;cd&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\QueryingProjectFileDemo\&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;'&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;cls&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$projects&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;ls&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-r&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-i&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; *.dbproj
&lt;/SPAN&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;$project&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;$projects&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;)
{
  &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$xml&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;new-object&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;System.Xml.XmlDocument&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;
  &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$xml&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="COLOR:#8b4513;"&gt;set_PreserveWhiteSpace&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;( &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$true&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; )
  &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$xml&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="COLOR:#8b4513;"&gt;Load&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$project&lt;/SPAN&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;$xpath = @{Start="/e:Project/e:ItemGroup/e:Build[e:SuppressWarnings=4151]/@Include"}&lt;/SPAN&gt;&lt;SPAN style="COLOR:#008000;"&gt;
&lt;/SPAN&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;$xpath = @{Start="/e:Project/e:ItemGroup/e:Build[contains(e:SuppressWarnings,'4151')]/@Include"}&lt;/SPAN&gt;&lt;SPAN style="COLOR:#008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;  &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$xpath&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; @{Start&lt;/SPAN&gt;&lt;SPAN style="COLOR:#ff0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;/e:Project/e:ItemGroup/e:Build[e:SuppressWarnings]/@Include&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;}
  &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$ns&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; @{ e &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;http://schemas.microsoft.com/developer/msbuild/2003&lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; }

  &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$xml&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; | &lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;Select-Xml&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-XPath&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$xpath&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;.Start  &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-Namespace&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800080;"&gt;$ns&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; |&lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;Select&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-Expand&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;Node&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; | &lt;/SPAN&gt;&lt;SPAN style="COLOR:#5f9ea0;FONT-WEIGHT:bold;"&gt;Select&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE:italic;COLOR:#5f9ea0;"&gt;-expand&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#800000;"&gt;Value&lt;/SPAN&gt;&lt;SPAN style="COLOR:#000000;"&gt;
}

&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;and here’s the output:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/image_60EABB8A.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_4716855B.png" width=765 height=102&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Nice reusable Powershell and SQL scripts – not bad for an evening’s work. Thank you to Kevin for allowing me to share his code.&lt;/P&gt;
&lt;P&gt;Don’t forget that these techniques can easily be adapted to query &lt;EM&gt;any&lt;/EM&gt; Visual Studio project file, they’re only XML documents after all! Doubtless many people out there already have code for doing this but nonetheless here is another offering to the great script library in the sky. Have fun!&lt;/P&gt;
&lt;P&gt;&lt;A href="http://twitter.com/jamiet"&gt;@Jamiet&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;This blog post was mentioned on &lt;/EM&gt;&lt;A href="http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-AutoTuneNET-Portable-Libraries-Facebook--Azure-SQLR2-BI"&gt;&lt;EM&gt;This Week on Channel 9&lt;/EM&gt;&lt;/A&gt;&lt;EM&gt;. Fast forward to 10m49s.&lt;/EM&gt;&lt;/P&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=32686" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/t-sql/default.aspx">t-sql</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/XML/default.aspx">XML</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Powershell/default.aspx">Powershell</category></item><item><title>A strategy for managing security for different environments using the Database Development Tools in Visual Studio 2010</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2010/07/21/a-strategy-for-managing-security-for-different-environments-using-the-database-development-tools-in-visual-studio-2010.aspx</link><pubDate>Wed, 21 Jul 2010 20:59:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:27217</guid><dc:creator>jamiet</dc:creator><slash:comments>11</slash:comments><comments>http://sqlblog.com/blogs/jamie_thomson/comments/27217.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/jamie_thomson/commentrss.aspx?PostID=27217</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/jamie_thomson/rsscomments.aspx?PostID=27217</wfw:comment><description>&lt;h3&gt;Intro&lt;/h3&gt;
&lt;p&gt;Of late I have been getting down and dirty with the Database Development tools in Visual Studio 2010. You may know this feature set by one of the plethora of other names it has had over recent years such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Visual Studio Team System for Database Professionals &lt;/li&gt;
&lt;li&gt;DBPro &lt;/li&gt;
&lt;li&gt;Datadude &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;For the rest of this post I’ll stick with the colloquial name that most people seem to recognise – datadude.&lt;/p&gt;
&lt;p&gt;Regardless of which moniker you prefer I’m hoping you recognise the feature set that I am referring to here which includes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Schema Compare &lt;/li&gt;
&lt;li&gt;Data Compare &lt;/li&gt;
&lt;li&gt;Offline database development &lt;/li&gt;
&lt;li&gt;T-SQL refactoring &lt;/li&gt;
&lt;li&gt;Database unit testing/Data generation &lt;/li&gt;
&lt;li&gt;MSBuild integration &lt;/li&gt;
&lt;li&gt;various other things… &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;I plan to write a detailed blog post in the coming weeks talking about my overall experiences with datadude but in the meantime I’m writing this blog post to focus on how I have chosen to manage security; by which I mean:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;logins &lt;/li&gt;
&lt;li&gt;users &lt;/li&gt;
&lt;li&gt;role membership &lt;/li&gt;
&lt;li&gt;user and role permissions &lt;/li&gt;&lt;/ul&gt;
&lt;hr&gt;

&lt;h3&gt;Security in Post-Deployment scripts&lt;/h3&gt;
&lt;p&gt;Datadude has built-in support for managing all of this stuff as we can see from this screenshot:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_4F758EED.png"&gt;&lt;img style="border-width:0px;display:inline;" class="wlDisabledImage" title="users roles logins in datadude" border="0" alt="users roles logins in datadude" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_0D8EA99F.png" width="676" height="433"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Notice that we have created a &lt;strong&gt;user&lt;/strong&gt;, a &lt;strong&gt;login &lt;/strong&gt;for that user and a &lt;strong&gt;role &lt;/strong&gt;into which we later want to add the user. They exist as explicit objects within our project which means that datadude “knows” about them and that has a number of advantages including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Datadude can include these objects in a schema compare &lt;/li&gt;
&lt;li&gt;Datadude can do dependency tracking thus enabling offline development (e.g. If the login that is referenced in the CREATE USER statement does not exist then a design-time error will be raised) &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;That should be enough to justify using datadude to manage users and roles however I have come across a limitation that prohibits us from doing so; we do not deploy the same security model to each of our environments. The reasons for this are very familiar to you I’m sure, we have people that require different permissions on different environments (e.g. our developers will want to be able to issue DDL and UPDATE/INSERT/DELETE on our development environment but we definitely don’t want them to have the same on production).&lt;/p&gt;
&lt;p&gt;As far as I can discern datadude does not have a good solution for dealing with this situation. I have not found a way of conditionally deploying objects depending on which environment we are deploying to. Actually that is not altogether true, we could have a Visual Studio configuration for each environment and include/exclude objects as we choose but that doesn’t play well with the build and deploy model of msbuild which requires that you build each one of those configurations; each of our builds takes about 10 minutes which, when multiplied by the number of environments, results in a total build time that takes too long for our continuous integration (CI) usage.&lt;/p&gt;
&lt;p&gt;Hence we needed a better way to deploy our security model – we chose to use PostDeployment scripts. PostDeployment scripts do exactly what they say on the tin – they are scripts that get run after datadude has deployed the objects that it knows about. They get called (using SQLCMD syntax) from the &lt;font face="Courier New"&gt;Script.PostDeployment.sql &lt;/font&gt;file that exists in every datadude project:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/cid_image002_png01CB274D_4ACF5E66.png"&gt;&lt;img style="border-width:0px;display:inline;" class="wlDisabledImage" title="post deployment script solution explorer" border="0" alt="post deployment script solution explorer" src="http://sqlblog.com/blogs/jamie_thomson/cid_image002_png01CB274D_thumb_6A120539.png" width="303" height="221"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;My chosen approach is to have a script called &lt;font face="Courier New"&gt;SecurityAdditionsWrapper.sql&lt;/font&gt; that gets called from &lt;font face="Courier New"&gt;Script.PostDeployment.sql&lt;/font&gt;. &lt;font face="Courier New"&gt;SecurityAdditionsWrapper.sql &lt;/font&gt;checks a SQLCMD variable to determine which environment is being deployed to and then calls the appropriate &lt;font face="Courier New"&gt;SecurityAdditionsXXX.sql &lt;/font&gt;script that is responsible for deploying the security model for that environment (where XXX is the environment).&lt;/p&gt;
&lt;p&gt;I then have 3 subfolders that contain all the individual CREATE USER, role membership and permissions scripts that get called from &lt;font face="Courier New"&gt;SecurityAdditionsXXX.sql&lt;/font&gt; as and when required.&lt;/p&gt;
&lt;p&gt;The screenshot below shows the contents of &lt;font face="Courier New"&gt;Script.PostDeployment.sql &lt;/font&gt;&amp;amp; &lt;font face="Courier New"&gt;SecurityAdditionsWrapper.sql&lt;/font&gt; and also the files as they exist in Solution Explorer:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/cid_image003_png01CB274F_7DBEEECD.png"&gt;&lt;img style="border-width:0px;display:inline;" class="wlDisabledImage" title="!cid_image003_png@01CB274F" border="0" alt="!cid_image003_png@01CB274F" src="http://sqlblog.com/blogs/jamie_thomson/cid_image003_png01CB274F_thumb_5969E47E.png" width="778" height="614"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Some things to notice:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;I have a SQLCMD variable called $(DeployType) that will contain the value “DEV”, “UAT” or “PRD” &lt;/li&gt;
&lt;li&gt;All of my security scripts exist in Post-Deployment&amp;nbsp; -&amp;gt; SecurityAdditions &lt;/li&gt;
&lt;li&gt;In the commented-out code you can see that I was trying to be clever and dynamically build the name of the file to be executed using the $(DeployType) variable – the thinking being that if we later added a new environment type I wouldn’t need to change this script. Unfortunately even though this is valid SQLCMD syntax it does not work in datadude; I have reported that issue on Connect as a bug (with repro) at &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/575383/datadude-valid-sqlcmd-syntax-throws-error-at-build-time"&gt;[Datadude] Valid SQLCMD syntax throws error at build time&lt;/a&gt;. &lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;You may be wondering how we get a value into that $(DeployType) variable when using msbuild. Well, its pretty simple when you know how. First you need to include the variable in the sqlcmdvars file for your datadude project:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/cid_image004_png01CB2755_5A129AA8.png"&gt;&lt;img style="border-width:0px;display:inline;" class="wlDisabledImage" title="!cid_image004_png@01CB2755" border="0" alt="!cid_image004_png@01CB2755" src="http://sqlblog.com/blogs/jamie_thomson/cid_image004_png01CB2755_thumb_0E46C3EF.png" width="430" height="272"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You then need to pass in the appropriate value to that variable at deploy-time. We are using &lt;a href="http://msdn.microsoft.com/en-us/library/dd193258.aspx"&gt;VSDBCMD.exe&lt;/a&gt; to run our deployments and the &lt;a href="http://msdn.microsoft.com/en-us/library/dd193283.aspx"&gt;syntax to pass in a value for a variable&lt;/a&gt; is /p:PropertyName=PropertyValue. We are calling VSDBCMD.exe from inside an msbuild script which therefore looks like this:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;&amp;lt;Exec&lt;/font&gt; &lt;font color="#ff0000"&gt;Command&lt;/font&gt;&lt;font color="#9b00d3"&gt;="..\Tools\VSDBCMD\vsdbcmd.exe /Action:Deploy /ConnectionString:'Data Source=$(DatabaseServer);Integrated Security=True;Pooling=False' /DeployToDatabase:+ /ManifestFile:.\MyDB.deploymanifest &lt;strong&gt;/p:DeployType=&amp;amp;quot;$(DeployType)&amp;amp;quot&lt;/strong&gt;; "&lt;/font&gt; &lt;font color="#0000ff"&gt;/&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;$(DeployType) is of course also a property within our msbuild file, which I am drawing attention to in the bold section above.&lt;/p&gt;
&lt;h3&gt;Wrap-Up&lt;/h3&gt;
&lt;p&gt;In conclusion, I am not saying that this is the &lt;i&gt;correct&lt;/i&gt; way to deploy a SQL Server security model using datadude, it just happens to be the method that I have chosen. I would really like to how people have solved this using datadude so if you have any anecdotes to share please put them in the comments.&lt;/p&gt;
&lt;hr&gt;

&lt;h3&gt;One more thing…&lt;/h3&gt;
&lt;p&gt;Cranking all of those files out by hand is a laborious undertaking, especially if you have lots of users with lots of permissions. In our case we introduced datadude to be used with an existing system hence we already had all our security setup on existing servers but we had no good way of getting it into the structure that I explained above. Powershell and SQLCMD to the rescue!&lt;/p&gt;
&lt;p&gt;I have produced a series of scripts that interrogate a named instance and produce all of the files that I explain above. Namely:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A file for each user which gets dropped into %SolutionRoot%\%ProjectName%\Scripts\Post-Deployment\Users\ &lt;/li&gt;
&lt;li&gt;A file for each principle that issues all the GRANT/DENY EXECUTE/SELECT/INSERT/UPDATE/DELETE for that principle, it gets dropped into %SolutionRoot%\%ProjectName%\Scripts\Post-Deployment\PermissionsSets\ &lt;/li&gt;
&lt;li&gt;A file that specifies all of the role memberships, for all database principles. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Creating the CREATE USER file and the file containing the permissions for each principle is&amp;nbsp;quite involved. For that we need some nested loops that loop over (a) all the databases for which you want to scripts users and (b) all the principles in each database. It then dumps the appropriate files into the appropriate folders and then you have the simple task of adding them to your project and calling them from your Post Deployment script.&lt;/p&gt;
&lt;p&gt;The files are stored in a zip folder on my SkyDrive at &lt;a title="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20100721/GeneratePermissions.zip" href="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20100721/GeneratePermissions.zip"&gt;http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20100721/GeneratePermissions.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To run the Powershell script simply unzip all the files into the root folder of your solution and issue:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&amp;gt;GeneratePermissions.ps1 -SQLInstance instanceName -Environment XXX&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;changing SQLInstance &amp;amp; XXX accordingly (the &lt;font face="Courier New"&gt;$Environment&lt;/font&gt; variable is simply a suffix that is added to the names of some of the generated files). The Powershell script contains more detailed notes within it in the comments section at the top.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_0A78F952.png"&gt;&lt;img style="border-width:0px;display:inline;" class="wlDisabledImage" title="powershell script comments" border="0" alt="powershell script comments" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_62664A32.png" width="739" height="273"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hope this helps!&lt;/p&gt;
&lt;p&gt;Disclaimer: I’m giving this away for free and I won’t be supporting it so use at your own peril (in other words, don’t come here complaining that it doesn’t work on your environment). On the other hand if you find a problem and are able to fix it – please let me know &lt;img class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://sqlblog.com/blogs/jamie_thomson/wlEmoticonsmile_19CC5B61.png"&gt;&lt;/p&gt;
&lt;p&gt;UPDATE: I did actually find some problems with the scripts and have now uploaded a new set. I'm confident that they'll work this time.&lt;/p&gt;
&lt;p&gt;UPDATE 2: I've updated the scripts again. They now create the SecurityAdditionsXXX.sql file as well as the individual CREATE USER &amp;amp; permissions files;&amp;nbsp;SecurityAdditionsXXX.sql contains all of the calls to the relevant scripts for environment XXX.&lt;/p&gt;
&lt;p&gt;SecurityAdditionsXXX.sql also issues all of the role membership statements as well. So just to clarify - you now no longer have a need to run the script that generates the role memberships - GeneratePermissions.ps1 takes care of everything.&lt;/p&gt;&lt;p&gt;UPDATE 3: Peter Schott has taken this, adapted it for hiw own needs, and sent it back to me so that I can share it here. His modified version of the scripts is at &lt;a href="http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20100721/GeneratePermissions%5E_PeterSchott.zip"&gt;http://cid-550f681dad532637.office.live.com/self.aspx/Public/BlogShare/20100721/GeneratePermissions%5E_PeterSchott.zip&lt;/a&gt;&amp;nbsp;and includes these changes (mainly to deal with roles):&lt;/p&gt;&lt;p&gt;1. Changed the Powershell script:&lt;br&gt;&amp;nbsp; * Added a section to handle role permissions. (really don't care for the way VS does it)&lt;br&gt;&amp;nbsp; * Tweaked the Database Principle section - for some reason, the variable in the PS script I extracted wasn't set properly so I just changed the names around&lt;br&gt;&amp;nbsp; * Added a bunch of lines of code to add to the Array. My Powershell's not too strong so wasn't sure about the best way to add new DBs/Projects to the DB Array. I ended up doing a bunch of sets. I know it's not ideal, but I just wanted to get it done one time.&lt;br&gt;&amp;nbsp; * Tweaked the section that creates the Users. If one of those logins doesn't exist, the grant permissions script would stop. Now I check to make sure that the login exists before the script runs.&amp;nbsp;I sometimes get empty (Login = [])&amp;nbsp; sections. No ideas on that yet. I fix or delete that file as appropriate.&lt;br&gt;&lt;br&gt;2. Added a "GetDatabaseRoleList.sql" file.&amp;nbsp; Gets the roles for the DB so we can run it through the Permissions file&lt;br&gt;&lt;br&gt;3. Permissions SQL file. I tweaked this with a query that UNIONs the object permissions with the Schema permissions. I didn't break it down further &lt;br&gt;like you did, but our permissions are so messed up right now that it doesn't matter much to me. (we have &lt;i&gt;far&lt;/i&gt; too many permissions granted to &lt;br&gt;individual users instead of roles because the prior DBA didn't understand the point of DB Roles for permissions and even then far too many permissions because we had a job that nightly granted all permissions on all objects to certain usernames :-P&amp;nbsp; )&lt;br&gt;&lt;/p&gt;&lt;p&gt;And one more change that needs to be made which Peter informed me of later: &lt;/p&gt;&lt;p&gt;Ended up changing the GeneratePermissions.ps1 file to change all of the Out-File &lt;br&gt;to "Out-File -width 500 ".&lt;br&gt;&lt;br&gt;After doing that, the permissions weren't truncated at 80 characters.&amp;nbsp; Also tweaked the Invoke-SQLCmd functions to use -MaxCharLength 500 so the output line would be long enough. That may have been overkill or there may be a better way to handle, but some of my permission lines were definitely longer than the allowed line lengths.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;P.S. I have used Powershell in the past but this is the first time I have really got into the inner workings of it and I’ve got to tell you – its just fantastic. The productivity you get is just incredible – if you don’t believe me have a look at the script herein and see how easy it is to generate a dataset from SQL Server and then loop over it inside your script. Its two lines of code - really fantastic stuff – I recommend any SQL Server pro go out and spend some time getting to know Powershell. &lt;img src="http://sqlblog.com/aggbug.aspx?PostID=27217" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sql+server/default.aspx">sql server</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Datadude/default.aspx">Datadude</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/msbuild/default.aspx">msbuild</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Security/default.aspx">Security</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Powershell/default.aspx">Powershell</category></item></channel></rss>