<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tim laqua dot com &#187; powershell</title>
	<atom:link href="http://timlaqua.com/tag/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://timlaqua.com</link>
	<description>Thoughts and Code from Tim Laqua</description>
	<lastBuildDate>Fri, 03 Feb 2012 23:12:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Monitoring and Starting Data Collector Sets with Powershell</title>
		<link>http://timlaqua.com/2011/10/monitoring-and-starting-data-collector-sets-with-powershell/</link>
		<comments>http://timlaqua.com/2011/10/monitoring-and-starting-data-collector-sets-with-powershell/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 01:33:24 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=801</guid>
		<description><![CDATA[I figure it's about time I posted an update to my previous post on Monitoring, Starting, and Stopping Perfmon Performance Counter Logs using VBScript. In the years since that post, a few operating systems came out and many much more interesting languages happened by. So this update is in Powershell. You could do it in [...]]]></description>
			<content:encoded><![CDATA[<p>I figure it's about time I posted an update to my previous post on <a href="http://timlaqua.com/2008/11/monitoring-starting-and-stopping-perfmon-performance-counter-logs-using-vbscript/" title="Monitoring, Starting, and Stopping Perfmon Performance Counter Logs using VBScript">Monitoring, Starting, and Stopping Perfmon Performance Counter Logs using VBScript</a>.  In the years since that post, a few operating systems came out and many much more interesting languages happened by.  So this update is in Powershell.  You could do it in pretty much any language, but Powershell seems to be my weapon of choice lately.</p>
<p>The basic premise here is that we want our Data Collector Sets to always be running.  Seems like a reasonable request, but for various reasons, Data Collector Sets just... stop.  This script should be run regularly (every 5 minutes?) to ensure that the sets keep collecting data.  In the event that the script finds some work to do, it will send you an email.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">#======= START Config ========</span>
<span style="color: #800080;">$emailServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;1.2.3.4&quot;</span>;
<span style="color: #800080;">$fromAddress</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;you@yourcompany.com&quot;</span>;
<span style="color: #800080;">$toAddress</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;you@yourcompany.com&quot;</span>;
<span style="color: #800080;">$ignorePattern</span> <span style="color: pink;">=</span> <span style="color: #800000;">'^(RandomCollectorSet|OSTest)$'</span>;
<span style="color: #008000;">#======== END Config =========</span>
&nbsp;
<span style="color: #800080;"><span style="color: #000080;">$Error</span>ActionPreference</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;SilentlyContinue&quot;</span>
<span style="color: #800080;">$serverName</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> env:computername;
<span style="color: #800080;">$emailBody</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>
&nbsp;
<span style="color: #800080;">$collectors</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: pink;">-</span>COM Pla.DataCollectorSetCollection;
<span style="color: #800080;">$collectors</span>.GetDataCollectorSets<span style="color: #000000;">&#40;</span><span style="color: #800080;">$null</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;Service\*&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #800080;">$collectors</span>._NewEnum <span style="color: pink;">|</span> <span style="color: pink;">?</span><span style="color: #000000;">&#123;</span><span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Status <span style="color: #FF0000;">-ne</span> <span style="color: #000000;">1</span> <span style="color: #FF0000;">-and</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Name <span style="color: #FF0000;">-notmatch</span> <span style="color: #800080;">$ignorePattern</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span>
	<span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Start<span style="color: #000000;">&#40;</span><span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Status <span style="color: #FF0000;">-eq</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$emailBody</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;Started $($_.Name)<span style="color: #008080; font-weight: bold;">`n</span>&quot;</span>
	<span style="color: #000000;">&#125;</span> <span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$emailBody</span> <span style="color: pink;">+=</span> <span style="color: #800000;">&quot;Failed to start $($_.Name)<span style="color: #008080; font-weight: bold;">`n</span>&quot;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>;
&nbsp;
<span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$emailBody</span> <span style="color: #FF0000;">-ne</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
  <span style="color: #800080;">$smtp</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> Net.Mail.SmtpClient<span style="color: #000000;">&#40;</span><span style="color: #800080;">$emailServer</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #800080;">$smtp</span>.Send<span style="color: #000000;">&#40;</span>
    <span style="color: #800000;">&quot;$serverName &lt;$fromAddress&gt;&quot;</span><span style="color: pink;">,</span> 
    <span style="color: #800080;">$toAddress</span><span style="color: pink;">,</span> 
    <span style="color: #800000;">&quot;Started Data Collector Set(s)&quot;</span><span style="color: pink;">,</span> 
    <span style="color: #800080;">$emailBody</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>If you want the script to keep any of the non-user created collectors running, modify the namespace parameter of the GetDataCollectorSets method call.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2011/10/monitoring-and-starting-data-collector-sets-with-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Revisiting Embedded Text Qualifiers and the SSIS Flat File Connection Manager</title>
		<link>http://timlaqua.com/2011/06/revisiting-embedded-text-qualifiers-and-the-ssis-flat-file-connection-manager/</link>
		<comments>http://timlaqua.com/2011/06/revisiting-embedded-text-qualifiers-and-the-ssis-flat-file-connection-manager/#comments</comments>
		<pubDate>Thu, 09 Jun 2011 01:45:42 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[ssis]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=607</guid>
		<description><![CDATA[To quickly summarize the problem at hand, the Flat File Connection Manager doesn't support embedded Text Qualifiers. The reason this is a big issue is because the most commonly used text qualifier is a double quote (&#34;) and that's also a commonly used punctuation mark. That means if you have a CSV to import and [...]]]></description>
			<content:encoded><![CDATA[<p>To quickly summarize the problem at hand, the Flat File Connection Manager doesn't support embedded Text Qualifiers.  The reason this is a big issue is because the most commonly used text qualifier is a double quote (&quot;) and that's also a commonly used punctuation mark.  That means if you have a CSV to import and lines that looks like this:<br />
<code><br />
"one","1","two","2","th""r""ee","3","asdf"<br />
"""left","right""","mid""dle","w"",tf","w,""tf",",""omg","omg"","<br />
</code></p>
<p>You would expect to import</p>
<table>
<tr>
<td>one</td>
<td>1</td>
<td>two</td>
<td>2</td>
<td>th"r"ee</td>
<td>3</td>
<td>asdf</td>
</tr>
<tr>
<td>"left</td>
<td>right"</td>
<td>mid"dle</td>
<td>w",tf</td>
<td>w,"tf</td>
<td>,"omg</td>
<td>omg",</td>
</tr>
</table>
<p>That's not what you get, you get an error.  I've seen a few different approaches to working around this known issue:</p>
<ul>
<li><a href="http://www.andrewdenhertog.com/tips/importing-csv-flat-files-in-ssis-dealing-with-double-quotes">Replacing embedded text qualifiers with some other token - &amp;quot; in this case</a></li>
<li><a href="http://www.ideaexcursion.com/2008/11/12/handling-embedded-text-qualifiers/">Import each file as a single column and parse the row in a script task, handling error rows</a></li>
</ul>
<p>What I'd like to explore in this post is using regular expressions to transform the entire file in to something that can be natively consumed by SSIS.  There are two options for dealing with this:</p>
<ul>
<li>Tokenizing the quotation marks found within the cells</li>
<li>Change the text qualifier</li>
</ul>
<p>I chose to change the text qualifier because SSIS natively supports multiple character text qualifiers.  This will allow me to pick something ridiculous that is incredibly unlikely to appear in the data naturally.  Changing the text qualifier also means we won't have to add any extra transformations as we would if we tokenized the embeded quotation marks (to turn them back in to quotation marks).<br />
<span id="more-607"></span><br />
Let's start out with the file we're importing so we have some text to test against (C:\SSISTextQualifier\Input.csv)</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&quot;one&quot;,&quot;1&quot;,&quot;two&quot;,&quot;2&quot;,&quot;th&quot;&quot;r&quot;&quot;ee&quot;,&quot;3&quot;,&quot;asdf&quot;
&quot;&quot;&quot;left&quot;,&quot;right&quot;&quot;&quot;,&quot;mid&quot;&quot;dle&quot;,&quot;w&quot;&quot;,tf&quot;,&quot;w,&quot;&quot;tf&quot;,&quot;,&quot;&quot;omg&quot;,&quot;omg&quot;&quot;,&quot;</pre></div></div>

<p>Now let's iron out the regular expression we're going to need.</p>
<p>We'll start out with grabbing a bunch of stuff between two double-quotes<br/><br />
<a href="http://timlaqua.com/wp-content/uploads/2011/06/Regex07.png"><img src="http://timlaqua.com/wp-content/uploads/2011/06/Regex07.png" alt="" title="Regex07" width="620" height="343" class="alignnone size-full wp-image-624" /></a><br />
<br/><br />
Ok, we don't just want a bunch of stuff - we want the stuff between each set of quotation marks - we make the * quantifier lazy with a question mark<br/><br />
<a href="http://timlaqua.com/wp-content/uploads/2011/06/Regex01.png"><img src="http://timlaqua.com/wp-content/uploads/2011/06/Regex01.png" alt="" title="Regex01" width="620" height="315" class="alignnone size-full wp-image-616" /></a><br />
<br/><br />
Better... but that th""r""ee is clearly wrong... we have to stop the final quotation mark from matching properly escaped quotation marks.  We can do that with a negative lookahead:<br/><br />
<a href="http://timlaqua.com/wp-content/uploads/2011/06/Regex12.png"><img src="http://timlaqua.com/wp-content/uploads/2011/06/Regex12.png" alt="" title="Regex12" width="620" height="343" class="alignnone size-full wp-image-677" /></a><br />
<br/><br />
That's different - notice that now properly escaped quotation marks aren't abnormally terminating the column match anymore, now they're just acting like normal characters.  We have to make a special exception for escaped quotation marks.  Those have to essentially count as a single character:<br/><br />
<a href="http://timlaqua.com/wp-content/uploads/2011/06/Regex08.png"><img src="http://timlaqua.com/wp-content/uploads/2011/06/Regex08.png" alt="" title="Regex08" width="620" height="343" class="alignnone size-full wp-image-627" /></a><br />
<br/><br />
Perfect - Now we can replace the text qualifiers with something awesome like |~| since we have matched the column content safely<br/><br />
<a href="http://timlaqua.com/wp-content/uploads/2011/06/Regex05.png"><img src="http://timlaqua.com/wp-content/uploads/2011/06/Regex05.png" alt="" title="Regex05" width="620" height="315" class="alignnone size-full wp-image-621" /></a></p>
<p>Now that we have our regex, we just have to decide how to execute.</p>
<h3>Plan A:  SSIS Script Task</h3>
<p>Create a new package with a single script task in it<br/><br />
<a href="http://timlaqua.com/wp-content/uploads/2011/06/SSIS01.png"><img src="http://timlaqua.com/wp-content/uploads/2011/06/SSIS01.png" alt="" title="SSIS01" width="660" height="418" class="alignnone size-full wp-image-637" /></a></p>
<p>Now edit the script (C#) and add the following up by the existing using statements:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.RegularExpressions</span><span style="color: #008000;">;</span></pre></div></div>

<p>Modify the Main method to look something like this (depending on your paths):</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            StreamReader sr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span>.<span style="color: #0000FF;">StreamReader</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">@&quot;C:\SSISTextQualifier\Input.csv&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span> allText <span style="color: #008000;">=</span> sr.<span style="color: #0000FF;">ReadToEnd</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            sr.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            StreamWriter sw <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StreamWriter<span style="color: #000000;">&#40;</span><span style="color: #666666;">@&quot;C:\SSISTextQualifier\InputCleaned.csv&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            sw.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>
                    Regex.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span>
                        allText, 
                        <span style="color: #666666;">@&quot;&quot;</span><span style="color: #666666;">&quot;((?:&quot;</span><span style="color: #666666;">&quot;&quot;</span><span style="color: #666666;">&quot;|.)*?)&quot;</span><span style="color: #666666;">&quot;(?!&quot;</span><span style="color: #666666;">&quot;)&quot;</span>, 
                        <span style="color: #666666;">@&quot;|~|$1|~|&quot;</span>
                    <span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\&quot;</span><span style="color: #008080; font-weight: bold;">\&quot;</span>&quot;</span>, <span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            sw.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Dts.<span style="color: #0000FF;">TaskResult</span> <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>ScriptResults.<span style="color: #0000FF;">Success</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span></pre></div></div>

<p>Then run that task and you will have a new file called C:\SSISTextQualifier\InputCleaned.csv that's text qualified by |~| and the escaped double quotes have been replaced with a single double quote.</p>
<h3>Plan B: Powershell</h3>
<p>Since we often call SSIS packages from the SQL Server Agent, we can easily add a Powershell step right before the SSIS package to copy and cleanse our file.  If that's the route you choose, your powershell step will look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">gc</span> C:\SSISTextQualifier\Input.csv <span style="color: pink;">|</span> 
<span style="color: pink;">%</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;"><span style="color: #000080;">$_</span></span> <span style="color: #FF0000;">-replace</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`&quot;</span>((?:<span style="color: #008080; font-weight: bold;">`&quot;</span><span style="color: #008080; font-weight: bold;">`&quot;</span>|.)*?)<span style="color: #008080; font-weight: bold;">`&quot;</span>(?!<span style="color: #008080; font-weight: bold;">`&quot;</span>)&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;|~|<span style="color: #008080; font-weight: bold;">`$</span>1|~|&quot;</span> <span style="color: #FF0000;">-replace</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`&quot;</span><span style="color: #008080; font-weight: bold;">`&quot;</span>&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`&quot;</span>&quot;</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> 
<span style="color: #008080; font-weight: bold;">sc</span> C:\SSISTextQualifier\InputCleaned2.csv</pre></div></div>

<h3>Final Steps</h3>
<p>However you got your data in to a new file (<strong>C:\SSISTextQualifier\InputCleaned.csv</strong> in my case) with a new text qualifier, you still have to then import the file.  This is done using our old friend the Flat File Connection Manager with the source being the newly minted clean file and with our new text qualifier set as |~|</p>
<p><a href="http://timlaqua.com/wp-content/uploads/2011/06/SSIS02.png"><img src="http://timlaqua.com/wp-content/uploads/2011/06/SSIS02.png" alt="" title="SSIS02" width="550" height="562" class="alignnone size-full wp-image-642" /></a></p>
<p>And that's pretty much it:<br/><br />
<a href="http://timlaqua.com/wp-content/uploads/2011/06/SSIS03.png"><img src="http://timlaqua.com/wp-content/uploads/2011/06/SSIS03.png" alt="" title="SSIS03" width="550" height="562" class="alignnone size-full wp-image-643" /></a></p>
<h3>Conclusion</h3>
<p>Personally, I think the Powershell plan is the cleanest and easiest to implement.  The code isn't hidden away in a script task, and it looks cool.  Doing it this way allows us to kind of abstract this "file fixing" from the SSIS data flows and let them do what they do best.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2011/06/revisiting-embedded-text-qualifiers-and-the-ssis-flat-file-connection-manager/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Restarting Automatic Services using Powershell</title>
		<link>http://timlaqua.com/2011/04/restarting-automatic-services-using-powershell/</link>
		<comments>http://timlaqua.com/2011/04/restarting-automatic-services-using-powershell/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 19:53:24 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=456</guid>
		<description><![CDATA[What? Why would you need to restart an automatic service? Because they die sometimes - there's probably some very good reasons for this, but I don't know them. What I do know is they die from time to time and don't come back. Sometimes they never get around to starting after a reboot. I run [...]]]></description>
			<content:encoded><![CDATA[<p>What?  Why would you need to restart an automatic service?  Because they die sometimes - there's probably some very good reasons for this, but I don't know them.  What I do know is they die from time to time and don't come back.  Sometimes they never get around to starting after a reboot.</p>
<p><em>I run the following Powershell script every 5 minutes to restart the ones that got tired:</em></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">#======= START Config ========</span>
<span style="color: #800080;">$emailServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;1.2.3.4&quot;</span>;
<span style="color: #800080;">$fromAddress</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;you@yourcompany.com&quot;</span>;
<span style="color: #800080;">$toAddress</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;you@yourcompany.com&quot;</span>;
<span style="color: #800080;">$ignorePattern</span> <span style="color: pink;">=</span> <span style="color: #800000;">'^(ShellHWDetection|MMCSS|sppsvc|clr_optimization.*)$'</span>;
<span style="color: #008000;">#======== END Config =========</span>
&nbsp;
<span style="color: #008080; font-weight: bold;">Get-WmiObject</span> Win32_Service <span style="color: pink;">|</span> 
<span style="color: pink;">?</span> <span style="color: #000000;">&#123;</span> 
  <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.StartMode <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">'Auto'</span> `
  <span style="color: #FF0000;">-and</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.State <span style="color: #FF0000;">-ne</span> <span style="color: #800000;">'Running'</span> `
  <span style="color: #FF0000;">-and</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Name <span style="color: #FF0000;">-notmatch</span> <span style="color: #800080;">$ignorePattern</span>
<span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> 
<span style="color: pink;">%</span> <span style="color: #000000;">&#123;</span> 
  <span style="color: #800080;">$svcName</span> <span style="color: pink;">=</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Name; 
  <span style="color: #800080;">$serverName</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> env:computername;
  <span style="color: #008080; font-weight: bold;">Start-Service</span> <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Name <span style="color: pink;">-</span>EA SilentlyContinue; 
  <span style="color: #800080;">$smtp</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> Net.Mail.SmtpClient<span style="color: #000000;">&#40;</span><span style="color: #800080;">$emailServer</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #800080;">$smtp</span>.Send<span style="color: #000000;">&#40;</span>
    <span style="color: #800000;">&quot;$serverName &lt;$fromAddress&gt;&quot;</span><span style="color: pink;">,</span> 
    <span style="color: #800080;">$toAddress</span><span style="color: pink;">,</span> 
    <span style="color: #800000;">&quot;Started service &quot;</span><span style="color: #800000;">&quot;$svcName&quot;</span><span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> 
    <span style="color: #800000;">&quot;Started service &quot;</span><span style="color: #800000;">&quot;$svcName&quot;</span><span style="color: #800000;">&quot; on $serverName.&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>$ignorePattern is a regular expression for identifying what services to ignore (so services that you don't care to try and restart).</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2011/04/restarting-automatic-services-using-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dealing With Long Running SSAS Queries using Powershell</title>
		<link>http://timlaqua.com/2011/04/dealing-with-long-running-ssas-queries-using-powershell/</link>
		<comments>http://timlaqua.com/2011/04/dealing-with-long-running-ssas-queries-using-powershell/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 17:27:06 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[ssas]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=462</guid>
		<description><![CDATA[So, your Analysis Services instance keeps eating all the memory on your server despite proper memory configuration? This happens when queries get too big for their britches - SSAS memory limits are basically soft limits. Whatever an active query requires in terms of resources, SSAS will attempt to provide it. Even if it has to [...]]]></description>
			<content:encoded><![CDATA[<p>So, your Analysis Services instance keeps eating all the memory on your server despite proper memory configuration?  This happens when queries get too big for their britches - SSAS memory limits are basically soft limits.  Whatever an active query requires in terms of resources, SSAS will attempt to provide it.  Even if it has to page the entire operating system out to disk to do it.  You can mitigate this with good cube design, better aggregations, user training, etc - but it's bound to happen.  When your cube gets big enough, one of your users will blow the entire server up.<span id="more-462"></span></p>
<p>First things fist - the original thought for this came form Chris Webb's article,  <a href="http://cwebbbi.wordpress.com/2008/12/04/killing-sessions-automatically-with-ssis/">Killing sessions automatically with SSIS</a>.  Now on to my solution - which is basically identical in theory, just implemented in PowerShell with an email notification at the end.</p>
<p><em>Create a SQL Agent job with a PowerShell step that runs the following script and schedule it to run every 30 seconds</em></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">#======= START Config ========</span>
<span style="color: #800080;">$asInstance</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;ssasinstance&quot;</span>;
<span style="color: #800080;">$emailServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;1.2.3.4&quot;</span>;
<span style="color: #800080;">$fromAddress</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;you@yourcompany.com&quot;</span>;
<span style="color: #800080;">$toAddress</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;you@yourcompany.com&quot;</span>;
<span style="color: #800080;">$maxQueryElapsedMS</span> <span style="color: pink;">=</span> <span style="color: #000000;">30000</span>;
<span style="color: #800080;">$bypassUserPattern</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;yourusername&quot;</span>;
<span style="color: #008000;">#======== END Config =========</span>
&nbsp;
<span style="color: #000000;">&#91;</span><span style="color: #008080;">System.Reflection.Assembly</span><span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.AnalysisServices.Xmla&quot;</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #000000;">&#91;</span>Microsoft.AnalysisServices.xmla.xmlaclient<span style="color: #000000;">&#93;</span><span style="color: #800080;">$client</span> <span style="color: pink;">=</span> 
  <span style="color: #008080; font-weight: bold;">new-object</span> Microsoft.AnalysisServices.Xmla.XmlaClient ;
<span style="color: #800080;">$client</span>.Connect<span style="color: #000000;">&#40;</span><span style="color: #800080;">$asInstance</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #800080;">$commands</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>;
<span style="color: #800080;">$sessions</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>;
<span style="color: #800080;">$client</span>.Discover<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;DISCOVER_COMMANDS&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">ref</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$commands</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #800080;">$client</span>.Discover<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;DISCOVER_SESSIONS&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">ref</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$sessions</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #800080;">$sessionsXml</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">xml</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$sessions</span>;
<span style="color: #800080;">$sessionsRows</span> <span style="color: pink;">=</span> <span style="color: #800080;">$sessionsXml</span>.<span style="color: #0000FF;">return</span>.root.row;
<span style="color: #800080;">$commandsXml</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">xml</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$commands</span>;
<span style="color: #800080;">$commandsRows</span> <span style="color: pink;">=</span> <span style="color: #800080;">$commandsXml</span>.<span style="color: #0000FF;">return</span>.root.row;
&nbsp;
<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$commandsRows</span><span style="color: #000000;">&#41;</span> 
<span style="color: #000000;">&#123;</span>
  <span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$row</span>.COMMAND_ELAPSED_TIME_MS <span style="color: #FF0000;">-gt</span> <span style="color: #800080;">$maxQueryElapsedMS</span> <span style="color: #FF0000;">-and</span> <span style="color: #800080;">$row</span>.COMMAND_TEXT <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;SELECT&quot;</span><span style="color: #000000;">&#41;</span> 
  <span style="color: #000000;">&#123;</span>
    <span style="color: #800080;">$spid</span> <span style="color: pink;">=</span> <span style="color: #800080;">$row</span>.SESSION_SPID;
    <span style="color: #800080;">$commandText</span> <span style="color: pink;">=</span> <span style="color: #800080;">$row</span>.COMMAND_TEXT;
    <span style="color: #800080;">$session</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$sessionsRows</span> <span style="color: pink;">|</span> <span style="color: pink;">?</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;"><span style="color: #000080;">$_</span></span>.SESSION_SPID <span style="color: #FF0000;">-eq</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$spid</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #800080;">$user</span> <span style="color: pink;">=</span> <span style="color: #800080;">$session</span>.SESSION_USER_NAME;
    <span style="color: #800080;">$db</span> <span style="color: pink;">=</span> <span style="color: #800080;">$session</span>.SESSION_CURRENT_DATABASE;
    <span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$user</span> <span style="color: #FF0000;">-notmatch</span> <span style="color: #800080;">$bypassUserPattern</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
      <span style="color: #800080;">$cancelXMLA</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&lt;Cancel xmlns=&quot;</span><span style="color: #800000;">&quot;http://schemas.microsoft.com/analysisservices/2003/engine&quot;</span><span style="color: #800000;">&quot;&gt;&lt;SPID&gt;$spid&lt;/SPID&gt;&lt;/Cancel&gt;&quot;</span>;
      <span style="color: #800080;">$client</span>.Send<span style="color: #000000;">&#40;</span><span style="color: #800080;">$cancelXMLA</span><span style="color: pink;">,</span> <span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #800080;">$smtp</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> Net.Mail.SmtpClient<span style="color: #000000;">&#40;</span><span style="color: #800080;">$emailServer</span><span style="color: #000000;">&#41;</span>; 
      <span style="color: #800080;">$smtp</span>.Send<span style="color: #000000;">&#40;</span>
        <span style="color: #800000;">&quot;$asInstance &lt;$fromAddress&gt;&quot;</span><span style="color: pink;">,</span> 
        <span style="color: #800080;">$toAddress</span><span style="color: pink;">,</span> 
        <span style="color: #800000;">&quot;Killed SPID: $spid&quot;</span><span style="color: pink;">,</span> 
        <span style="color: #800000;">&quot;SPID $spid was detected as the owner of a long running query and was killed.<span style="color: #008080; font-weight: bold;">`r</span><span style="color: #008080; font-weight: bold;">`n</span>User: $user<span style="color: #008080; font-weight: bold;">`r</span><span style="color: #008080; font-weight: bold;">`n</span>DB: $db<span style="color: #008080; font-weight: bold;">`r</span><span style="color: #008080; font-weight: bold;">`n</span><span style="color: #008080; font-weight: bold;">`r</span><span style="color: #008080; font-weight: bold;">`n</span>$commandText&quot;</span>
      <span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$client</span>.Disconnect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>Great.  Now sessions with active queries (aka "commands" with the word "SELECT" in them) taking over 30 seconds will be cancelled and we'll get an email w/ the query so we can debug!  So you wake up the next morning and Japan called - a bunch of their pivots errored out last night and they're not happy.  Hmm...  Pry should have warned someone before we started cancelling queries...</p>
<p><strong>Phase 2:  Turn off the query/session killer, turn on the logging</strong></p>
<p>Create the Log table:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>LongRunningMDXQueryLog<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span>
	<span style="color: #808080;">&#91;</span>SPID<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">INT</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>CommandStartTime<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATETIME</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>Username<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATABASE</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>ElapsedTimeMS<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">INT</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>CommandText<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>
<span style="color: #808080;">&#41;</span></pre></div></div>

<p>Create the MERGE proc to handle log entries</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">PROCEDURE</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>LongRunningMDXQueryLog_Merge<span style="color: #808080;">&#93;</span>
	 @SPID <span style="color: #0000FF;">INT</span>
	,@CommandStartTime <span style="color: #0000FF;">DATETIME</span>
	,@Username <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>
	,@<span style="color: #0000FF;">DATABASE</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>
	,@ElapsedTimeMS <span style="color: #0000FF;">INT</span>
	,@CommandText <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
	;MERGE LongRunningMDXQueryLog a <span style="color: #0000FF;">USING</span>
	<span style="color: #808080;">&#40;</span>
		<span style="color: #0000FF;">SELECT</span>
			 @SPID 
			,<span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>@CommandStartTime <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">DATETIME</span><span style="color: #808080;">&#41;</span>
			,@Username 
			,@<span style="color: #0000FF;">DATABASE</span>
			,@ElapsedTimeMS 
			,@CommandText 
	<span style="color: #808080;">&#41;</span> b
	<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>SPID<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>CommandStartTime<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>Username<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATABASE</span><span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>ElapsedTimeMS<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>CommandText<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">ON</span>
	<span style="color: #808080;">&#40;</span>a.<span style="color: #808080;">&#91;</span>SPID<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>SPID<span style="color: #808080;">&#93;</span>
	 <span style="color: #808080;">AND</span> a.<span style="color: #808080;">&#91;</span>CommandStartTime<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>CommandStartTime<span style="color: #808080;">&#93;</span>
	 <span style="color: #808080;">AND</span> a.<span style="color: #808080;">&#91;</span>Username<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>Username<span style="color: #808080;">&#93;</span>
	 <span style="color: #808080;">AND</span> a.<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATABASE</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATABASE</span><span style="color: #808080;">&#93;</span>
	 <span style="color: #808080;">AND</span> a.<span style="color: #808080;">&#91;</span>CommandText<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>CommandText<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">NOT</span> MATCHED <span style="color: #0000FF;">THEN</span>
	<span style="color: #0000FF;">INSERT</span>
			   <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>SPID<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>CommandStartTime<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>Username<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATABASE</span><span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>ElapsedTimeMS<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>CommandText<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>
		 <span style="color: #0000FF;">VALUES</span>
			   <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>SPID<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>CommandStartTime<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>Username<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATABASE</span><span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>ElapsedTimeMS<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>CommandText<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">WHEN</span> MATCHED <span style="color: #0000FF;">THEN</span>
	<span style="color: #0000FF;">UPDATE</span>
	<span style="color: #0000FF;">SET</span>
		<span style="color: #808080;">&#91;</span>ElapsedTimeMS<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>ElapsedTimeMS<span style="color: #808080;">&#93;</span>
	;
<span style="color: #0000FF;">END</span></pre></div></div>

<p>Create a job to run the following Powershell script every 30 seconds:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">#======= START Config ========</span>
<span style="color: #800080;">$asInstance</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;ssasinstance&quot;</span>;
<span style="color: #800080;">$logConnectionString</span> <span style="color: pink;">=</span> 
  <span style="color: #800000;">&quot;server=sqlserverinstance;&quot;</span> <span style="color: pink;">+</span> 
  <span style="color: #800000;">&quot;database=databaseYouCreatedTheLogTableIn;&quot;</span> <span style="color: pink;">+</span> 
  <span style="color: #800000;">&quot;trusted_connection=true;&quot;</span>;
<span style="color: #800080;">$maxQueryElapsedMS</span> <span style="color: pink;">=</span> <span style="color: #000000;">30000</span>;
<span style="color: #008000;">#======== END Config =========</span>
&nbsp;
<span style="color: #000000;">&#91;</span><span style="color: #008080;">System.Reflection.Assembly</span><span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.AnalysisServices.Xmla&quot;</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #000000;">&#91;</span>Microsoft.AnalysisServices.xmla.xmlaclient<span style="color: #000000;">&#93;</span><span style="color: #800080;">$client</span> <span style="color: pink;">=</span> 
  <span style="color: #008080; font-weight: bold;">new-object</span> Microsoft.AnalysisServices.Xmla.XmlaClient ;
<span style="color: #800080;">$client</span>.Connect<span style="color: #000000;">&#40;</span><span style="color: #800080;">$asInstance</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #800080;">$commands</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>;
<span style="color: #800080;">$sessions</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>;
<span style="color: #800080;">$client</span>.Discover<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;DISCOVER_COMMANDS&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">ref</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$commands</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #800080;">$client</span>.Discover<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;DISCOVER_SESSIONS&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">ref</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$sessions</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #800080;">$sessionsXml</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">xml</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$sessions</span>;
<span style="color: #800080;">$sessionsRows</span> <span style="color: pink;">=</span> <span style="color: #800080;">$sessionsXml</span>.<span style="color: #0000FF;">return</span>.root.row;
<span style="color: #800080;">$commandsXml</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">xml</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$commands</span>;
<span style="color: #800080;">$commandsRows</span> <span style="color: pink;">=</span> <span style="color: #800080;">$commandsXml</span>.<span style="color: #0000FF;">return</span>.root.row;
&nbsp;
<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$commandsRows</span><span style="color: #000000;">&#41;</span> 
<span style="color: #000000;">&#123;</span>
  <span style="color: #800080;">$elapsedTimeMS</span> <span style="color: pink;">=</span> <span style="color: #800080;">$row</span>.COMMAND_ELAPSED_TIME_MS;
  <span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$elapsedTimeMS</span> <span style="color: #FF0000;">-gt</span> <span style="color: #800080;">$maxQueryElapsedMS</span> <span style="color: #FF0000;">-and</span> <span style="color: #800080;">$row</span>.COMMAND_TEXT <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;SELECT&quot;</span><span style="color: #000000;">&#41;</span> 
  <span style="color: #000000;">&#123;</span>
    <span style="color: #800080;">$spid</span> <span style="color: pink;">=</span> <span style="color: #800080;">$row</span>.SESSION_SPID;
    <span style="color: #800080;">$commandText</span> <span style="color: pink;">=</span> <span style="color: #800080;">$row</span>.COMMAND_TEXT <span style="color: #FF0000;">-replace</span> <span style="color: #800000;">&quot;'&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;''&quot;</span>;
    <span style="color: #800080;">$session</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$sessionsRows</span> <span style="color: pink;">|</span> <span style="color: pink;">?</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;"><span style="color: #000080;">$_</span></span>.SESSION_SPID <span style="color: #FF0000;">-eq</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$spid</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #800080;">$user</span> <span style="color: pink;">=</span> <span style="color: #800080;">$session</span>.SESSION_USER_NAME;
    <span style="color: #800080;">$db</span> <span style="color: pink;">=</span> <span style="color: #800080;">$session</span>.SESSION_CURRENT_DATABASE;
    <span style="color: #800080;">$commandStartTime</span> <span style="color: pink;">=</span> 
      <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$row</span>.COMMAND_START_TIME <span style="color: #FF0000;">-replace</span> <span style="color: #800000;">'\.\d+$'</span><span style="color: pink;">,</span> <span style="color: #800000;">''</span> <span style="color: #FF0000;">-replace</span> <span style="color: #800000;">'T'</span><span style="color: pink;">,</span> <span style="color: #800000;">' '</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #800080;">$sqlConn</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Data.SQLClient.SQLConnection<span style="color: #000000;">&#40;</span><span style="color: #800080;">$logConnectionString</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #800080;">$sqlConn</span>.Open<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #800080;">$sqlCommand</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Data.SQLClient.SQLCommand;
    <span style="color: #800080;">$sqlCommand</span>.Connection <span style="color: pink;">=</span> <span style="color: #800080;">$sqlConn</span>;
    <span style="color: #800080;">$sqlCommand</span>.CommandText <span style="color: pink;">=</span> 
      <span style="color: #800000;">&quot;EXEC LongRunningMDXQueryLog_Merge &quot;</span> <span style="color: pink;">+</span> 
        <span style="color: #800000;">&quot;$spid, &quot;</span> <span style="color: pink;">+</span>
        <span style="color: #800000;">&quot;'$commandStartTime', &quot;</span> <span style="color: pink;">+</span> 
        <span style="color: #800000;">&quot;'$user', &quot;</span> <span style="color: pink;">+</span> 
        <span style="color: #800000;">&quot;'$db', &quot;</span> <span style="color: pink;">+</span> 
        <span style="color: #800000;">&quot;$elapsedTimeMS, &quot;</span> <span style="color: pink;">+</span> 
        <span style="color: #800000;">&quot;'$commandText'&quot;</span>;
    <span style="color: #800080;">$sqlCommand</span>.ExecuteNonQuery<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #800080;">$sqlConn</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$client</span>.Disconnect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>And now you have a table filled with queries that will be cancelled (read: "error out") when the query killing job is running.  So now you fix it:</p>
<ol>
<li>locate these users</li>
<li>figure out what crazy pivots are causing the problem</li>
<li>Refactor the pivot OR determine what dimensionality is missing from the cube</li>
</ol>
<p>Once you go a day or so w/ a quiet log table, you can turn on the query killer and go on your merry way.  It's been suggested that we should send the user an email - let them know that it wasn't an error... that we cancelled their query.  Maybe - but honestly, you should probably email or call them personally to hash it out.  If it happens once, chalk it up to happenstance.  If it continues to occur, it's time for some user training and/or requirements gathering.</p>
<p>The real problem is that most end users don't know that 30 seconds is ridiculously long - they shouldn't have to wait that long.  Not only does it hurt them, it hurts others using the system as well.</p>
<p><em><strong>UPDATE:</strong>  You may want to, at some point, actually view one of these monster queries to see what on earth they were querying for.  Over a certain size, getting it out of SSMS can be pretty troublesome - A query similar to the following should do the trick:</em></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">DECLARE @SQLcommand VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4000</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">SET</span> @SQLcommand <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'bcp &quot;select CommandText 
from Database.dbo.LongRunningMDXQueryLog 
where SPID = 511519&quot; 
queryout &quot;c:<span style="color: #000099; font-weight: bold;">\o</span>utput.dtsx&quot; -T -c'</span>
&nbsp;
EXEC xp_cmdshell @SQLcommand</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2011/04/dealing-with-long-running-ssas-queries-using-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>VersionOne Nag: Reminding Us To Burn Our Points</title>
		<link>http://timlaqua.com/2010/02/versionone-nag-reminding-us-to-burn-our-points/</link>
		<comments>http://timlaqua.com/2010/02/versionone-nag-reminding-us-to-burn-our-points/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 04:19:41 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[version one]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=341</guid>
		<description><![CDATA[You'll forget - we all do. After a hard day of work, the last thing that pops in to your head is "hey, I should go update this story in VersionOne before I go home." Oh no, the only thing you're thinking about is how bad traffic will be, what you're having for dinner, your [...]]]></description>
			<content:encoded><![CDATA[<p>You'll forget - we all do.  After a hard day of work, the last thing that pops in to your head is "hey, I should go update this story in VersionOne before I go home."  Oh no, the only thing you're thinking about is how bad traffic will be, what you're having for dinner, your trip to Seattle, which bar has the best drink specials tonight, etc.  So accepting that we forget to burn points now and then, why don't we just make a script to remind us?  While you're at it, might as well add a reminder for when you accidentally close a story without setting the ToDo points to zero.</p>
<p>Luckily, since you obviously use VersionOne (because it's the gold standard), there's an API for that:<br />
<span id="more-341"></span><br />
<em>Note:  The following script will request your VersionOne username and password via Read-Host - if you want this to run every day at 4pm, you need to embed your username and password somewhere (securestring support in powershell is helpful, but still - nothing's perfect in this scenario unless you can use LDAP auth)</em></p>
<p><strong>PowerShell script: v1Nag.ps1</strong></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$emailFrom</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;whoever.replies@shouldgoto.com&quot;</span>
<span style="color: #800080;">$emailSMTPServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;your.smtpserver.com&quot;</span>
<span style="color: #800080;">$teamName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Your Team Name in VersionOne&quot;</span>
&nbsp;
<span style="color: #800080;">$url</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;https://wwwXXX.v1host.com/yourhostingid/&quot;</span>
<span style="color: #800080;">$username</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #800000;">&quot;User&quot;</span>
<span style="color: #800080;">$password</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #008080; font-style: italic;">-assecurestring</span> <span style="color: #800000;">&quot;Password&quot;</span>
&nbsp;
<span style="color: #800080;">$password</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.Runtime.InteropServices.Marshal<span style="color: #000000;">&#93;</span>::PtrToStringAuto<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>System.Runtime.InteropServices.Marshal<span style="color: #000000;">&#93;</span>::SecureStringToBSTR<span style="color: #000000;">&#40;</span><span style="color: #800080;">$password</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$apiClient</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">resolve-path</span> <span style="color: #800000;">&quot;versionone.sdk.apiclient.dll&quot;</span>
<span style="color: #800080;">$objectModel</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">resolve-path</span> <span style="color: #800000;">&quot;versionone.sdk.objectmodel.dll&quot;</span>
<span style="color: #000000;">&#91;</span>Reflection.Assembly<span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadFrom</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$apiClient</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">&gt;</span> <span style="color: #800080;">$NULL</span>
<span style="color: #000000;">&#91;</span>Reflection.Assembly<span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadFrom</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$objectModel</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">&gt;</span> <span style="color: #800080;">$NULL</span>
<span style="color: #800080;">$v1</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> VersionOne.SDK.ObjectModel.V1Instance<span style="color: #000000;">&#40;</span> <span style="color: #800080;">$url</span><span style="color: pink;">,</span> <span style="color: #800080;">$username</span><span style="color: pink;">,</span> <span style="color: #800080;">$password</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$v1</span>.Validate<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$sf</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> VersionOne.SDK.ObjectModel.Filters.StoryFilter
<span style="color: #800080;">$v1</span>.Get.Iterations<span style="color: #000000;">&#40;</span><span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: pink;">?</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.IsActive <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$sf</span>.Iteration.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;"><span style="color: #000080;">$_</span></span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$v1</span>.Get.Teams<span style="color: #000000;">&#40;</span><span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: pink;">?</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Name <span style="color: #FF0000;">-match</span> <span style="color: #800080;">$teamName</span> <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$sf</span>.Team.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;"><span style="color: #000080;">$_</span></span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> 
<span style="color: #800080;">$stories</span> <span style="color: pink;">=</span> <span style="color: #800080;">$v1</span>.Get.Stories<span style="color: #000000;">&#40;</span><span style="color: #800080;">$sf</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$memberDetail</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$story</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$stories</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$owner</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$story</span>.Owners<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: pink;">!</span><span style="color: #800080;">$memberDetail</span>.Contains<span style="color: #000000;">&#40;</span><span style="color: #800080;">$owner</span>.ID<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> 		
			<span style="color: #800080;">$md</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> PSObject <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> Email<span style="color: pink;">,</span> DetailEstimate<span style="color: pink;">,</span> ToDo<span style="color: pink;">,</span> Effort<span style="color: pink;">,</span> EffortToday<span style="color: pink;">,</span> DoneWithToDo
			<span style="color: #800080;">$md</span>.Email <span style="color: pink;">=</span> <span style="color: #800080;">$owner</span>.Email;
			<span style="color: #800080;">$md</span>.DetailEstimate <span style="color: pink;">=</span> <span style="color: #000000;">0</span>;
			<span style="color: #800080;">$md</span>.ToDo <span style="color: pink;">=</span> <span style="color: #000000;">0</span>;
			<span style="color: #800080;">$md</span>.Effort <span style="color: pink;">=</span> <span style="color: #000000;">0</span>;
			<span style="color: #800080;">$md</span>.EffortToday <span style="color: pink;">=</span> <span style="color: #000000;">0</span>;
			<span style="color: #800080;">$md</span>.DoneWithToDo <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #800080;">$memberDetail</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$owner</span>.ID<span style="color: pink;">,</span> <span style="color: #800080;">$md</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #800080;">$memberDetail</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$owner</span>.ID<span style="color: #000000;">&#93;</span>.ToDo <span style="color: pink;">+=</span> <span style="color: #800080;">$story</span>.ToDo;
		<span style="color: #800080;">$memberDetail</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$owner</span>.ID<span style="color: #000000;">&#93;</span>.DetailEstimate <span style="color: pink;">+=</span> <span style="color: #800080;">$story</span>.DetailEstimate;
&nbsp;
		<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$story</span>.ToDo <span style="color: #FF0000;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #FF0000;">-and</span> <span style="color: #800080;">$story</span>.Status.CurrentValue <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;Done&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #800080;">$memberDetail</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$owner</span>.ID<span style="color: #000000;">&#93;</span>.DoneWithToDo <span style="color: pink;">+=</span> <span style="color: #800080;">$story</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$effortRecord</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$story</span>.GetEffortRecords<span style="color: #000000;">&#40;</span><span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #800080;">$memberDetail</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$owner</span>.ID<span style="color: #000000;">&#93;</span>.Effort <span style="color: pink;">+=</span> <span style="color: #800080;">$effortRecord</span>.Value;
			<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$effortRecord</span>.CreateDate <span style="color: #FF0000;">-ge</span> <span style="color: #000000;">&#91;</span>DateTime<span style="color: #000000;">&#93;</span>::Today<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #800080;">$memberDetail</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$owner</span>.ID<span style="color: #000000;">&#93;</span>.EffortToday <span style="color: pink;">+=</span> <span style="color: #800080;">$effortRecord</span>.Value;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #800080;">$smtp</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> Net.Mail.SmtpClient<span style="color: #000000;">&#40;</span><span style="color: #800080;">$emailSMTPServer</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$memberDetail</span>.Values <span style="color: pink;">|</span> <span style="color: pink;">?</span><span style="color: #000000;">&#123;</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.EffortToday <span style="color: #FF0000;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #FF0000;">-and</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.ToDo <span style="color: #FF0000;">-gt</span> <span style="color: #000000;">0</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$smtp</span>.Send<span style="color: #000000;">&#40;</span><span style="color: #800080;">$emailFrom</span><span style="color: pink;">,</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Email<span style="color: pink;">,</span> <span style="color: #800000;">&quot;V1 Nag: No Points Burned Down Today&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;Please make sure you have recorded any effort completed on your stories for the day.&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #800080;">$memberDetail</span>.Values <span style="color: pink;">|</span> <span style="color: pink;">?</span><span style="color: #000000;">&#123;</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.DoneWithToDo.Count <span style="color: #FF0000;">-gt</span> <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$smtp</span>.Send<span style="color: #000000;">&#40;</span><span style="color: #800080;">$emailFrom</span><span style="color: pink;">,</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Email<span style="color: pink;">,</span> <span style="color: #800000;">&quot;V1 Nag: Story Marked As Done With ToDo Balance&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;Please make sure you have zero'd out ToDo on your Completed/Done stories.&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span></pre></div></div>

<p>You'll need to download the .NET SDK and build the requisite DLLs from:<br />
<a href="http://community.versionone.com/Downloads/default.aspx">http://community.versionone.com/Downloads/default.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2010/02/versionone-nag-reminding-us-to-burn-our-points/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

