<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Greg&#039;s Blog</title>
	<atom:link href="https://gregcaporale.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://gregcaporale.wordpress.com</link>
	<description>My tech repository</description>
	<lastBuildDate>Thu, 23 Feb 2012 15:50:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='gregcaporale.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>https://secure.gravatar.com/blavatar/fe1f4196ee25d2f91bb0a08227094559?s=96&#038;d=https%3A%2F%2Fs-ssl.wordpress.com%2Fi%2Fbuttonw-com.png</url>
		<title>Greg&#039;s Blog</title>
		<link>https://gregcaporale.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="https://gregcaporale.wordpress.com/osd.xml" title="Greg&#039;s Blog" />
	<atom:link rel='hub' href='https://gregcaporale.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Using sFTP in SQL Server SSIS</title>
		<link>https://gregcaporale.wordpress.com/2012/02/23/using-sftp-in-sql-server-ssis/</link>
		<comments>https://gregcaporale.wordpress.com/2012/02/23/using-sftp-in-sql-server-ssis/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 13:55:00 +0000</pubDate>
		<dc:creator>gregcaporale</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[sFTP]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">https://gregcaporale.wordpress.com/?p=134</guid>
		<description><![CDATA[On several occasions I have had to use SSIS to export data from a SQL database, and then transfer that data to a third party via sFTP.  SQL Server SSIS has an FTP task built in but it does not natively support sFTP.  There are several commercial products (Eldos Software, /n Software, CozyRoc) out on the market [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=134&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>On several occasions I have had to use SSIS to export data from a SQL database, and then transfer that data to a third party via sFTP.  SQL Server SSIS has an FTP task built in but it does not natively support sFTP.  There are several commercial products (<a href="http://www.eldos.com/bizcrypto/" target="_blank">Eldos Software</a>, <a href="http://www.nsoftware.com/ssis/default.aspx" target="_blank">/n Software</a>, <a href="http://www.cozyroc.com/" target="_blank">CozyRoc</a>) out on the market that can be used to add that functionality into SSIS but I am going to talk about using a free utility called <a href="http://www.winscp.net/" target="_blank">WinSCP</a> to accomplish this task.</p>
<p>The first step is to download and install WinSCP, you will need to do this on the SQL server that will be running the SSIS package.  Once you have installed WinSCP you should create a connection to the distant sFTP server in WinSCP so you can test and confirm that you can connect to it.  Create and name a saved session so that you can call that session from your script later.  I will name this session “MySecureFTP”.</p>
<p><a href="http://gregcaporale.files.wordpress.com/2012/02/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://gregcaporale.files.wordpress.com/2012/02/image_thumb.png?w=390&#038;h=294" alt="image" width="390" height="294" border="0" /></a></p>
<p>&nbsp;</p>
<p>Once you have done that you will need to create a WinSCP script to transfer your files.  For examples of scripts see the <a href="http://winscp.net/eng/docs/scripting" target="_blank">WinSCP documentation</a>.  Here is a very basic script that I created to copy a csv file.</p>
<blockquote><p>&nbsp;</p>
<p>option batch on</p>
<p>option confirm off</p>
<p>open MySecureFTP</p>
<p>put c:\outbound\*.csv /inbounddirectory/</p>
<p>exit</p></blockquote>
<p>After testing the script by running it from a command prompt and confirming that it works, you are ready to step into SSIS and call it from your workflow.</p>
<p>In Microsoft Visual Studio in your SSIS Package, go to the Control Flow tab and from your toolbox add an “Execute Process Task” to the workflow.  It should look like this after you’ve added it.</p>
<p><a href="http://gregcaporale.files.wordpress.com/2012/02/image1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://gregcaporale.files.wordpress.com/2012/02/image_thumb1.png?w=394&#038;h=290" alt="image" width="394" height="290" border="0" /></a></p>
<p>&nbsp;</p>
<p>Double click the Execute Process Task to open the Task Editor.  You should now have a window like this.</p>
<p><a href="http://gregcaporale.files.wordpress.com/2012/02/image2.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://gregcaporale.files.wordpress.com/2012/02/image_thumb2.png?w=452&#038;h=417" alt="image" width="452" height="417" border="0" /></a></p>
<p>Go to the Process section on the left and then you will need to fill out some information.</p>
<p><a href="http://gregcaporale.files.wordpress.com/2012/02/image3.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://gregcaporale.files.wordpress.com/2012/02/image_thumb3.png?w=494&#038;h=392" alt="image" width="494" height="392" border="0" /></a></p>
<p>In the executable line you will need to fill out the correct path to the WinSCP executable.  Mine was in the (x86) directory but it may be different for your computer.</p>
<p>Then in the Arguments line you will need to put the <span style="color:#0000ff;">/script= </span><span style="color:#000000;">switch and then the path to that script.  I also included the <span style="color:#0000ff;">/log= </span>switch to log the execution to a file.  That way I can go back and review the FTP connection and make sure everything was a success.  </span></p>
<p><span style="color:#000000;">You may need to add an entry for the WorkingDirectory if you do not use absolute paths in your script.  I didn’t require it.  </span></p>
<p><span style="color:#000000;">Now you can build your SSIS package and deploy it.  That’s all that you need to do.  </span></p>
<p><span style="color:#000000;"> </span></p>
<br />Filed under: <a href='https://gregcaporale.wordpress.com/category/system-admin/sql-server/'>SQL Server</a> Tagged: <a href='https://gregcaporale.wordpress.com/tag/sftp/'>sFTP</a>, <a href='https://gregcaporale.wordpress.com/tag/sql-server/'>SQL Server</a>, <a href='https://gregcaporale.wordpress.com/tag/ssis/'>SSIS</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporale.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporale.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporale.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporale.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregcaporale.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregcaporale.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregcaporale.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregcaporale.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporale.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporale.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporale.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporale.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporale.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporale.wordpress.com/134/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=134&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gregcaporale.wordpress.com/2012/02/23/using-sftp-in-sql-server-ssis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/dea0839821c850747cf92f7fa87e09e0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">gregcaporale</media:title>
		</media:content>

		<media:content url="http://gregcaporale.files.wordpress.com/2012/02/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://gregcaporale.files.wordpress.com/2012/02/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://gregcaporale.files.wordpress.com/2012/02/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://gregcaporale.files.wordpress.com/2012/02/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Now for a little VB Script</title>
		<link>https://gregcaporale.wordpress.com/2012/02/16/now-for-a-little-vb-script/</link>
		<comments>https://gregcaporale.wordpress.com/2012/02/16/now-for-a-little-vb-script/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 15:21:15 +0000</pubDate>
		<dc:creator>gregcaporale</dc:creator>
				<category><![CDATA[VB Script]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://gregcaporale.wordpress.com/?p=118</guid>
		<description><![CDATA[I was going through some old files and thought I would post this one as a good example of using VBScript. I had a request to automate the upload of a file to an FTP site.  This example dates back to 2006 so I know there are better ways to do this now, but it is a good example [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=118&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was going through some old files and thought I would post this one as a good example of using VBScript.</p>
<p>I had a request to automate the upload of a file to an FTP site.  This example dates back to 2006 so I know there are better ways to do this now, but it is a good example of the flexibility of VB Scripting.</p>
<p><span style="color:#008000;">&#8216; VBScript source code</span></p>
<p><span style="color:#0000ff;">Dim</span> Fso : <span style="color:#0000ff;">Set</span> Fso = CreateObject(<span style="color:#993300;">&#8220;Scripting.FileSystemObject&#8221;</span>)<br />
<span style="color:#0000ff;">Dim</span> WshNetwork : <span style="color:#0000ff;">Set</span> WshNetwork = CreateObject(<span style="color:#993300;">&#8220;Wscript.Network&#8221;</span>)<br />
<span style="color:#0000ff;">Dim</span> WshShell : <span style="color:#0000ff;">Set</span> WshShell = CreateObject(<span style="color:#993300;">&#8220;WScript.Shell&#8221;</span>)<br />
<span style="color:#0000ff;">Const</span> LogFile =<span style="color:#993300;"> &#8220;C:\VBScript\FTP.log&#8221;</span><br />
<span style="color:#008000;">&#8216;Declares the log file.</span><br />
<span style="color:#0000ff;">Set</span> FSO = CreateObject(<span style="color:#993300;">&#8220;Scripting.FileSystemObject&#8221;</span>)<br />
<span style="color:#0000ff;">Dim</span> strFileName : strFileName = <span style="color:#993300;">&#8220;C:\VBScript\holdings.csv&#8221;</span></p>
<p><span style="color:#008000;">&#8216;Checks to see if the file is ready.</span><br />
<span style="color:#0000ff;">If not</span> Fso.FileExists(strFileName) <span style="color:#0000ff;">then</span><br />
<span style="color:#008000;">&#8216;File is not ready exit out and wait</span><br />
<span style="color:#0000ff;">Set</span> WshShell = WScript.CreateObject(<span style="color:#993300;">&#8220;WScript.Shell&#8221;</span>)<br />
RunString = <span style="color:#993300;">&#8220;%comspec% /c echo ************************ &#8220;</span> &amp; WeekDayName(WeekDay(Now), True) &amp;<span style="color:#993300;"> &#8221; &#8220;</span> &amp; Now &amp; <span style="color:#993300;">&#8221; FILE NOT READY ************************ &#8220;</span><br />
<span style="color:#0000ff;">Return</span> = WshShell.Run(RunString &amp; &#8221; &gt;&gt; &#8221; &amp; LogFile &amp; &#8221; 2&gt;&amp;1&#8243;, 0, <span style="color:#0000ff;">TRUE</span>)<br />
WScript.quit<br />
<span style="color:#0000ff;">Else</span></p>
<p>RunCmd</p>
<p><span style="color:#0000ff;">Sub</span> RunCmd()<br />
<span style="color:#0000ff;">Set</span> WshShell = WScript.CreateObject(<span style="color:#993300;">&#8220;WScript.Shell&#8221;</span>)<br />
RunString = <span style="color:#993300;">&#8220;%comspec% /c echo ********************************************** &#8220;</span><br />
<span style="color:#0000ff;">Return</span> = WshShell.Run(RunString &amp; <span style="color:#993300;">&#8221; &gt;&gt; &#8220;</span> &amp; LogFile &amp; <span style="color:#993300;">&#8221; 2&gt;&amp;1&#8243;</span>, 0, <span style="color:#0000ff;">TRUE</span>)<br />
RunString =<span style="color:#993300;"> &#8220;%comspec% /c echo &#8220;</span> &amp; WeekDayName(WeekDay(Now), True) &amp; &#8221; &#8221; &amp; Now &amp; <span style="color:#993300;">&#8220;, &#8220;</span>&amp; strFileName &amp; <span style="color:#993300;">&#8221; is available &#8211; sending via FTP&#8221;</span><br />
<span style="color:#0000ff;">Return</span> = WshShell.Run(RunString &amp; <span style="color:#993300;">&#8221; &gt;&gt; &#8220;</span> &amp; LogFile &amp;<span style="color:#993300;"> &#8221; 2&gt;&amp;1&#8243;</span>, 0, <span style="color:#0000ff;">TRUE</span>)<br />
RunString =<span style="color:#993300;"> &#8220;%comspec% /c echo ********************************************** &#8220;</span><br />
<span style="color:#0000ff;">Return</span> = WshShell.Run(RunString &amp; <span style="color:#993300;">&#8221; &gt;&gt; &#8220;</span> &amp; LogFile &amp; <span style="color:#993300;">&#8221; 2&gt;&amp;1&#8243;</span>, 0, <span style="color:#0000ff;">TRUE</span>)<br />
<span style="color:#008000;">&#8216;FTP the file to client</span><br />
RunString = <span style="color:#993300;">&#8220;%comspec% /c %WINDIR%\System32\ftp.exe -i -n -s:C:\VBScript\instructions.txt &#8220;</span><br />
<span style="color:#0000ff;"> Return </span>= WshShell.Run(RunString &amp; <span style="color:#993300;">&#8221; &gt;&gt; &#8220;</span> &amp; LogFile &amp; <span style="color:#993300;">&#8221; 2&gt;&amp;1&#8243;</span>, 0, <span style="color:#0000ff;">TRUE</span>)<br />
RunString = <span style="color:#993300;">&#8220;%comspec% /c echo ********************************************** &#8220;</span><br />
<span style="color:#0000ff;">Return</span> = WshShell.Run(RunString &amp; <span style="color:#993300;">&#8221; &gt;&gt; &#8220;</span> &amp; LogFile &amp; <span style="color:#993300;">&#8221; 2&gt;&amp;1&#8243;</span>, 0, <span style="color:#0000ff;">TRUE</span>)<br />
RunString = <span style="color:#993300;">&#8220;%comspec% /c echo FINISHED: &#8220;</span> &amp; WeekDayName(WeekDay(Now),<span style="color:#0000ff;"> True</span>) &amp; <span style="color:#993300;">&#8221; &#8220;</span> &amp; Now<br />
<span style="color:#0000ff;">Return</span> = WshShell.Run(RunString &amp; <span style="color:#993300;">&#8221; &gt;&gt; &#8220;</span> &amp; LogFile &amp; <span style="color:#993300;">&#8221; 2&gt;&amp;1&#8243;</span>, 0, <span style="color:#0000ff;">TRUE</span>)<br />
RunString = <span style="color:#993300;">&#8220;%comspec% /c echo ********************************************** &#8220;</span><br />
<span style="color:#0000ff;">Return</span> = WshShell.Run(RunString &amp; <span style="color:#993300;">&#8221; &gt;&gt; &#8220;</span> &amp; LogFile &amp; <span style="color:#993300;">&#8221; 2&gt;&amp;1&#8243;</span>, 0, <span style="color:#0000ff;">TRUE</span>)<br />
<span style="color:#0000ff;">Set</span> WshShell = <span style="color:#0000ff;">Nothing</span><br />
<span style="color:#0000ff;font-size:small;"><span style="color:#0000ff;font-size:small;">End Sub</span></span><br />
<span style="color:#0000ff;font-size:small;"><span style="color:#0000ff;font-size:small;">End</span></span></p>
<p><span style="color:#000000;font-size:small;"><span style="font-size:small;">Basically this script will check to see if a file exists and if it does it will send the file via FTP to a remote location and log all the output to a log file.   This is a good simple script to quickly and repeatedly perform a task and log it. </span></span></p>
<br />Filed under: <a href='https://gregcaporale.wordpress.com/category/vb-script/'>VB Script</a>, <a href='https://gregcaporale.wordpress.com/category/system-admin/windows-server/'>Windows Server</a> Tagged: <a href='https://gregcaporale.wordpress.com/tag/scripting/'>scripting</a>, <a href='https://gregcaporale.wordpress.com/tag/vb-script/'>VB Script</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporale.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporale.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporale.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporale.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregcaporale.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregcaporale.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregcaporale.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregcaporale.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporale.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporale.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporale.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporale.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporale.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporale.wordpress.com/118/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=118&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gregcaporale.wordpress.com/2012/02/16/now-for-a-little-vb-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/dea0839821c850747cf92f7fa87e09e0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">gregcaporale</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting Up PowerShell 2010</title>
		<link>https://gregcaporale.wordpress.com/2012/02/10/setting-up-powershell-2010/</link>
		<comments>https://gregcaporale.wordpress.com/2012/02/10/setting-up-powershell-2010/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 16:39:06 +0000</pubDate>
		<dc:creator>gregcaporale</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Common Install Issues]]></category>
		<category><![CDATA[SharePoint2010]]></category>

		<guid isPermaLink="false">http://gregcaporale.wordpress.com/?p=113</guid>
		<description><![CDATA[Today I was setting up PowerShell 2010 for testing on a VM and I ran into an issue during the install that is apparently quite common. I had successfully installed the prerequisites and was attempting to install the actual product when I got the following error. Setup is unable to proceed due to the following [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=113&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I was setting up PowerShell 2010 for testing on a VM and I ran into an issue during the install that is apparently quite common. I had successfully installed the prerequisites and was attempting to install the actual product when I got the following error.</p>
<p><span style="color:#3366ff;">Setup is unable to proceed due to the following error(s):</span><br />
<span style="color:#3366ff;"> A system restart from a previous installation or update is pending. Restart your computer and run setup to continue.</span><br />
<span style="color:#3366ff;"> For the list of pre-requisites needed to install the product please refer to:</span><br />
<span style="color:#3366ff;"> http://go.microsoft.com/fwlink/?LinkId=106209</span><br />
<span style="color:#3366ff;"> Correct the issue(s) listed above and re-run setup.</span></p>
<p><span style="color:#333333;">After doing some research I found this link at <a href="http://blogs.technet.com/b/wbaer/archive/2009/12/11/common-microsoft-sharepoint-server-2010-installation-issues-and-resolutions.aspx" target="_blank">Microsoft&#8217;s TechNet</a> site about common installation issues.  </span></p>
<p><span style="color:#333333;">The fix for my dilemma was to find this registry key </span></p>
<p><span style="color:#333333;"><strong>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations</strong> </span></p>
<p><span style="color:#333333;">To delete the orphaned PendingFileRenameOperations registry key  </span></p>
<ol>
<li>Open a registry editor, such as Regedit.exe or Regedt32.exe.</li>
<li>Navigate to <strong>HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\</strong></li>
<li>In the right navigation pane, right-click the<strong> PendingFileRenameOperations</strong> key and select <strong>Delete</strong>.</li>
<li>Close Registry Editor.</li>
</ol>
<p>After deleting the registry key (MAKE A BACKUP JUST IN CASE) I was able to continue on and complete my installation of SharePoint 2010.</p>
<br />Filed under: <a href='https://gregcaporale.wordpress.com/category/sharepoint/'>SharePoint</a>, <a href='https://gregcaporale.wordpress.com/category/system-admin/windows-server/'>Windows Server</a> Tagged: <a href='https://gregcaporale.wordpress.com/tag/common-install-issues/'>Common Install Issues</a>, <a href='https://gregcaporale.wordpress.com/tag/sharepoint2010/'>SharePoint2010</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporale.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporale.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporale.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporale.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregcaporale.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregcaporale.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregcaporale.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregcaporale.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporale.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporale.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporale.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporale.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporale.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporale.wordpress.com/113/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=113&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gregcaporale.wordpress.com/2012/02/10/setting-up-powershell-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/dea0839821c850747cf92f7fa87e09e0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">gregcaporale</media:title>
		</media:content>
	</item>
		<item>
		<title>Using PowerShell to map a network drive</title>
		<link>https://gregcaporale.wordpress.com/2012/02/03/using-powershell-to-map-a-network-drive/</link>
		<comments>https://gregcaporale.wordpress.com/2012/02/03/using-powershell-to-map-a-network-drive/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 18:51:01 +0000</pubDate>
		<dc:creator>gregcaporale</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[System Admin]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Login Script]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[VPN]]></category>

		<guid isPermaLink="false">http://gregcaporale.wordpress.com/?p=98</guid>
		<description><![CDATA[Recently my CFO purchased a new computer for his home office.  He wanted to be able to VPN into the office and have access to all of his network shares and applications.  After installing all his applications I was trying to decide on how to go about mapping his network drives after he logged onto [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=98&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently my CFO purchased a new computer for his home office.  He wanted to be able to VPN into the office and have access to all of his network shares and applications.  After installing all his applications I was trying to decide on how to go about mapping his network drives after he logged onto the VPN.  I could have used a plain old batch file but once again I decided I could do a better job using PowerShell.</p>
<p>So, I started researching what I wanted to do.</p>
<p>Since his home PC was not a part of the office domain he would need to authenticate before he could access those network shares.  So, I decided to use the cmdlet <span style="color:#0000ff;">Get-Credential</span> to prompt him for his username and password.</p>
<p>Then I started working with the cmdlet <span style="color:#0000ff;">New-PSDrive</span> which did a good job of mapping a drive and allowed the credentials to be passed in.  However, I quickly discovered that using that cmdlet only allows access to that mapped drive within that PowerShell instance.  This was a deal breaker.  I wanted to have him run the PowerShell Script and have access to the drives outside of powershell.  So I did some more searching and found I could use the following code to make this work.<br />
<span style="color:#800080;">$creds</span><span style="color:#ff0000;">=</span><span style="color:#5f9ea0;font-weight:bold;">Get-Credential</span></p>
<p><span style="color:#800080;">$map</span><span style="color:#000000;">=</span><span style="color:#5f9ea0;font-weight:bold;">New-Object</span><span style="color:#5f9ea0;font-style:italic;">-ComObject </span><span style="color:#800000;">WScript.Network</span></p>
<p><span style="color:#800080;">$map</span><span style="color:#000000;">.MapNetworkDrive(</span><span style="color:#800000;">&#8220;</span><span style="color:#800000;">H:</span><span style="color:#800000;">&#8220;</span><span style="color:#000000;">,</span><span style="color:#800000;">&#8220;</span><span style="color:#800000;">\\SVR1\Users</span><span style="color:#800000;">&#8220;</span><span style="color:#000000;">,</span><span style="color:#000000;">0</span><span style="color:#000000;">,</span><span style="color:#800080;">$creds</span><span style="color:#000000;">.UserName,</span><span style="color:#800080;">$creds</span><span style="color:#000000;">.GetNetworkCredential().Password)<br />
</span><br />
<span style="color:#800080;">$map</span><span style="color:#000000;">.MapNetworkDrive(</span><span style="color:#800000;">&#8220;</span><span style="color:#800000;">I:</span><span style="color:#800000;">&#8220;</span><span style="color:#000000;">,</span><span style="color:#800000;">&#8220;</span><span style="color:#800000;">\\SVR1\Admin</span><span style="color:#800000;">&#8220;</span><span style="color:#000000;">,</span><span style="color:#000000;">0</span><span style="color:#000000;">)<br />
</span><br />
<span style="color:#800080;">$map</span><span style="color:#000000;">.MapNetworkDrive(</span><span style="color:#800000;">&#8220;</span><span style="color:#800000;">M:</span><span style="color:#800000;">&#8220;</span><span style="color:#000000;">,</span><span style="color:#800000;">&#8220;</span><span style="color:#800000;">\\SVR1\Data</span><span style="color:#800000;">&#8220;</span><span style="color:#000000;">,</span><span style="color:#000000;">0</span><span style="color:#000000;">)<br />
</span><br />
<span style="color:#800080;">$map</span><span style="color:#000000;">.MapNetworkDrive(</span><span style="color:#800000;">&#8220;</span><span style="color:#800000;">N:</span><span style="color:#800000;">&#8220;</span><span style="color:#000000;">,</span><span style="color:#800000;">&#8220;</span><span style="color:#800000;">\\SVR1\Software</span><span style="color:#800000;">&#8220;</span><span style="color:#000000;">,</span><span style="color:#000000;">0</span><span style="color:#000000;">)<br />
</span><br />
This script works fine for my basic purposes for now. But I have ideas to expand upon it and maybe use a foreach loop to reduce the amount of lines of code.</p>
<br />Filed under: <a href='https://gregcaporale.wordpress.com/category/powershell/'>PowerShell</a>, <a href='https://gregcaporale.wordpress.com/category/system-admin/'>System Admin</a>, <a href='https://gregcaporale.wordpress.com/category/system-admin/windows-server/'>Windows Server</a> Tagged: <a href='https://gregcaporale.wordpress.com/tag/login-script/'>Login Script</a>, <a href='https://gregcaporale.wordpress.com/tag/powershell-2/'>Powershell</a>, <a href='https://gregcaporale.wordpress.com/tag/vpn/'>VPN</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporale.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporale.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporale.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporale.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregcaporale.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregcaporale.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregcaporale.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregcaporale.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporale.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporale.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporale.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporale.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporale.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporale.wordpress.com/98/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=98&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gregcaporale.wordpress.com/2012/02/03/using-powershell-to-map-a-network-drive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/dea0839821c850747cf92f7fa87e09e0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">gregcaporale</media:title>
		</media:content>
	</item>
		<item>
		<title>Using PowerShell to copy files and send via email</title>
		<link>https://gregcaporale.wordpress.com/2012/01/24/using-powershell-to-copy-files-and-send-via-email/</link>
		<comments>https://gregcaporale.wordpress.com/2012/01/24/using-powershell-to-copy-files-and-send-via-email/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 19:23:00 +0000</pubDate>
		<dc:creator>gregcaporale</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[System Admin]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[FileCopy]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">https://gregcaporale.wordpress.com/?p=96</guid>
		<description><![CDATA[I was reading Joe Keohan’s Blog about copying files via PowerShell and that got me to thinking about a process I already had.&#160; Each night we copy files from a shared folder and post them to our intranet site for internal use.&#160; We currently are using a batch file to handle this but I thought [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=96&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was reading <a href="http://jkeohan.wordpress.com/2010/04/16/copy-folder-contents-using-powershell/" target="_blank">Joe Keohan’s Blog</a> about copying files via PowerShell and that got me to thinking about a process I already had.&#160; Each night we copy files from a shared folder and post them to our intranet site for internal use.&#160; We currently are using a batch file to handle this but I thought it was time to rewrite it in PowerShell.&#160; </p>
<p>I had two main processes that I needed to handle.&#160; The first was to copy the files to the local folder for the intranet and the second was to send an email to someone with those files attached so he can open them on his mobile device.&#160; </p>
<p>So the first step of my script was to define some variables to stand in for my file locations.&#160; </p>
<pre><span style="color:#800080;">$SourceDir</span><span style="color:#000000;"> </span><span style="color:#ff0000;">=</span><span style="color:#000000;"> </span><span style="color:#800000;">&quot;</span><span style="color:#800000;">\\SVR1\data\Reports\Trading\*.pdf</span><span style="color:#800000;">&quot;</span><span style="color:#000000;">
</span><span style="color:#800080;">$DestDir</span><span style="color:#000000;"> </span><span style="color:#ff0000;">=</span><span style="color:#000000;"> </span><span style="color:#800000;">&quot;</span><span style="color:#800000;">c:\inetpub\intranet\research\reports\</span><span style="color:#800000;">&quot;</span><span style="color:#000000;">
</span><span style="color:#800080;">$BlotterSource</span><span style="color:#000000;"> </span><span style="color:#ff0000;">=</span><span style="color:#000000;"> </span><span style="color:#800000;">&quot;</span><span style="color:#800000;">\\SVR1\data\Reports\Blotters\*.pdf</span><span style="color:#800000;">&quot;</span></pre>
<p>Then I use the Test-Path cmdlet to determine if the reports exist at the source location.&#160; Normally this cmdlet would return True if the files exist and False if they do not.&#160; But I use it in an If statement to say if it evaluates to True then do something else.&#160; The something else is to start the file copy.&#160; </p>
<p>&#160;</p>
<pre><span style="color:#0000ff;">If</span><span style="color:#000000;"> (</span><span style="color:#5f9ea0;font-weight:bold;">Test-path</span><span style="color:#000000;"> </span><span style="color:#800080;">$SourceDir</span><span style="color:#000000;"> )
{
    </span><span style="color:#5f9ea0;font-weight:bold;">Copy-Item</span><span style="color:#000000;"> </span><span style="color:#800080;">$SourceDir</span><span style="color:#000000;"> </span><span style="font-style:italic;color:#5f9ea0;">-Destination</span><span style="color:#000000;"> </span><span style="color:#800080;">$DestDir</span><span style="color:#000000;"> </span><span style="font-style:italic;color:#5f9ea0;">-Force</span><span style="color:#000000;">
}

</span><span style="color:#0000ff;">If</span><span style="color:#000000;"> (</span><span style="color:#5f9ea0;font-weight:bold;">Test-path</span><span style="color:#000000;"> </span><span style="color:#800080;">$BlotterSource</span><span style="color:#000000;">)
{
    </span><span style="color:#5f9ea0;font-weight:bold;">Copy-Item</span><span style="color:#000000;"> </span><span style="color:#800080;">$BlotterSource</span><span style="color:#000000;"> </span><span style="font-style:italic;color:#5f9ea0;">-Destination</span><span style="color:#000000;"> </span><span style="color:#800080;">$DestDir</span><span style="color:#000000;"> </span><span style="font-style:italic;color:#5f9ea0;">-Force</span><span style="color:#000000;">
}</span></pre>
<p>I do this twice, once for one location and then again for the second location.&#160; </p>
<p>And once my script is finished copying the files I use the send-mailmessage cmdlet to email the files to the recipient.&#160; Since I have multiple files I’d like to attach I use a Get-ChildItem cmdlet to get all the file names and pipe them into the send-mailmessage cmd.&#160; </p>
<p>This is what the finished script looks like.&#160; </p>
<p><span style="color:#800080;">$SourceDir</span><span style="color:#000000;"> </span><span style="color:#ff0000;">=</span><span style="color:#000000;"> </span><span style="color:#800000;">&quot;</span><span style="color:#800000;">\\SVR1\data\Reports\Trading\*.pdf</span><span style="color:#800000;">&quot;</span><span style="color:#000000;"> </span></p>
<p><span style="color:#000000;"></span><span style="color:#800080;">$DestDir</span><span style="color:#000000;"> </span><span style="color:#ff0000;">=</span><span style="color:#000000;"> </span><span style="color:#800000;">&quot;</span><span style="color:#800000;">c:\inetpub\intranet\research\reports\</span><span style="color:#800000;">&quot;</span><span style="color:#000000;"> </span></p>
<p><span style="color:#000000;"></span><span style="color:#800080;">$BlotterSource</span><span style="color:#000000;"> </span><span style="color:#ff0000;">=</span><span style="color:#000000;"> </span><span style="color:#800000;">&quot;</span><span style="color:#800000;">\\SVR1\data\Reports\Blotters\*.pdf</span><span style="color:#800000;">&quot;</span><span style="color:#000000;"> </span></p>
<p><span style="color:#000000;"></span><span style="color:#0000ff;">If</span><span style="color:#000000;"> (</span><span style="color:#5f9ea0;font-weight:bold;">Test-path</span><span style="color:#000000;"> </span><span style="color:#800080;">$SourceDir</span><span style="color:#000000;"> ) </span></p>
<p><span style="color:#000000;">{ </span><span style="color:#5f9ea0;font-weight:bold;">Copy-Item</span><span style="color:#000000;"> </span><span style="color:#800080;">$SourceDir</span><span style="color:#000000;"> </span><span style="font-style:italic;color:#5f9ea0;">-Destination</span><span style="color:#000000;"> </span><span style="color:#800080;">$DestDir</span><span style="color:#000000;"> </span><span style="font-style:italic;color:#5f9ea0;">-Force</span><span style="color:#000000;"> } </span></p>
<p><span style="color:#000000;"></span><span style="color:#0000ff;">If</span><span style="color:#000000;"> (</span><span style="color:#5f9ea0;font-weight:bold;">Test-path</span><span style="color:#000000;"> </span><span style="color:#800080;">$BlotterSource</span><span style="color:#000000;">) </span></p>
<p><span style="color:#000000;">{ </span><span style="color:#5f9ea0;font-weight:bold;">Copy-Item</span><span style="color:#000000;"> </span><span style="color:#800080;">$BlotterSource</span><span style="color:#000000;"> </span><span style="font-style:italic;color:#5f9ea0;">-Destination</span><span style="color:#000000;"> </span><span style="color:#800080;">$DestDir</span><span style="color:#000000;"> </span><span style="font-style:italic;color:#5f9ea0;">-Force</span><span style="color:#000000;"> } </span></p>
<p><span style="color:#000000;"></span><span style="color:#5f9ea0;font-weight:bold;">Get-ChildItem</span><span style="color:#000000;"> </span><span style="color:#800080;">$DestDir</span><span style="color:#000000;"> | </span><span style="color:#5f9ea0;font-weight:bold;">Where</span><span style="color:#000000;"> {</span><span style="color:#ff0000;">-NOT</span><span style="color:#000000;"> </span><span style="color:#800080;">$_</span><span style="color:#000000;">.PSIsContainer} | </span><span style="color:#5f9ea0;font-weight:bold;">foreach</span><span style="color:#000000;"> {</span><span style="color:#800080;">$_</span><span style="color:#000000;">.fullname} | </span><span style="color:#5f9ea0;font-weight:bold;">send-mailmessage</span><span style="color:#000000;"> </span><span style="font-style:italic;color:#5f9ea0;">-from</span><span style="color:#000000;"> </span><span style="color:#800000;">&quot;</span><span style="color:#800000;">Reporting &lt;reporting@anyone.com&gt;</span><span style="color:#800000;">&quot;</span><span style="color:#000000;"> </span><span style="font-style:italic;color:#5f9ea0;">-to</span><span style="color:#000000;"> </span><span style="color:#800000;">&quot;</span><span style="color:#800000;">Jonathan &lt;jonathan@anyone.com&gt;</span><span style="color:#800000;">&quot;</span><span style="color:#000000;">, </span><span style="color:#800000;">&quot;</span><span style="color:#800000;">Rob &lt;rob@anyone.com&gt;</span><span style="color:#800000;">&quot;</span><span style="color:#000000;"> </span><span style="font-style:italic;color:#5f9ea0;">-Cc</span><span style="color:#000000;"> </span><span style="color:#800000;">&quot;</span><span style="color:#800000;">Greg &lt;greg@anyone.com</span><span style="color:#800000;">&quot;</span><span style="color:#000000;">&gt; </span><span style="font-style:italic;color:#5f9ea0;">-subject</span><span style="color:#000000;"> </span><span style="color:#800000;">&quot;</span><span style="color:#800000;">Daily Research Reports</span><span style="color:#800000;">&quot;</span><span style="color:#000000;"> </span><span style="font-style:italic;color:#5f9ea0;">-smtpServer</span><span style="color:#000000;"> </span><span style="color:#800000;">mailserver.anyone.com</span><span style="color:#000000;"> </span><span style="font-style:italic;color:#5f9ea0;">-Body</span><span style="color:#000000;"> </span><span style="color:#800000;">&quot;</span><span style="color:#800000;">Here are the daily research files for your review</span><span style="color:#800000;">&quot;</span><span style="color:#000000;"> </span></p>
<p>Now that the script is done I just schedule it via Windows Task Scheduler and we’re all set.&#160; Now the files will get copied and emailed quickly and efficiently. </p>
<br />Filed under: <a href='https://gregcaporale.wordpress.com/category/powershell/'>PowerShell</a>, <a href='https://gregcaporale.wordpress.com/category/system-admin/'>System Admin</a>, <a href='https://gregcaporale.wordpress.com/category/system-admin/windows-server/'>Windows Server</a> Tagged: <a href='https://gregcaporale.wordpress.com/tag/email/'>email</a>, <a href='https://gregcaporale.wordpress.com/tag/filecopy/'>FileCopy</a>, <a href='https://gregcaporale.wordpress.com/tag/powershell-2/'>Powershell</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporale.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporale.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporale.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporale.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregcaporale.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregcaporale.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregcaporale.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregcaporale.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporale.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporale.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporale.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporale.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporale.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporale.wordpress.com/96/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=96&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gregcaporale.wordpress.com/2012/01/24/using-powershell-to-copy-files-and-send-via-email/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/dea0839821c850747cf92f7fa87e09e0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">gregcaporale</media:title>
		</media:content>
	</item>
		<item>
		<title>Updated PowerShell script to loop through files for printing.</title>
		<link>https://gregcaporale.wordpress.com/2012/01/23/updated-powershell-script-to-loop-through-files-for-printing/</link>
		<comments>https://gregcaporale.wordpress.com/2012/01/23/updated-powershell-script-to-loop-through-files-for-printing/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 16:43:16 +0000</pubDate>
		<dc:creator>gregcaporale</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[acrobat]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[printing]]></category>

		<guid isPermaLink="false">https://gregcaporale.wordpress.com/?p=88</guid>
		<description><![CDATA[After finishing my script from the previous post I thought there has to be a better way to write this and reduce the lines of code.&#160; Not that 5 separate lines is a lot.&#160; But, if the list of items to print grew larger say to 15 documents, and was in different subdirectories then it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=88&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After finishing my script from the previous post I thought there has to be a better way to write this and reduce the lines of code.&#160; Not that 5 separate lines is a lot.&#160; But, if the list of items to print grew larger say to 15 documents, and was in different subdirectories then it might get complicated.&#160; So, I set about trying to find a way to use the <font color="#0000ff">ForEach-Object</font> cmd.&#160; After some trial and error I have come up with this.&#160; </p>
<p><span style="color:#ff4500;">$Directory</span> <span style="color:#a9a9a9;">=</span> <span style="color:#8b0000;">&quot;\\SVR1\DATA\Reports\Trading\&quot;</span> </p>
<p><span style="color:#0000ff;">Get-ChildItem</span> <span style="color:#000080;">-path</span> <span style="color:#ff4500;">$Directory</span> <span style="color:#000080;">-recurse</span> <span style="color:#000080;">-include</span> <span style="color:#8a2be2;">*.pdf</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">ForEach-Object</span> <span style="color:#000000;">{</span><span style="color:#0000ff;">Start-Process</span> <span style="color:#000080;">-FilePath</span> <span style="color:#ff4500;">$_</span><span style="color:#a9a9a9;">.</span><span style="color:#000000;">fullname</span> <span style="color:#000080;">-Verb</span> <span style="color:#8a2be2;">Print</span> <span style="color:#000080;">-PassThru</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">%</span><span style="color:#000000;">{</span><span style="color:#0000ff;">sleep</span> <span style="color:#800080;">10</span><span style="color:#000000;">;</span><span style="color:#ff4500;">$_</span><span style="color:#000000;">}</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">kill</span> <span style="color:#000000;">}</span> </p>
<p>&#160;</p>
<p>This will loop through the “Trading” directory and all subdirectories and print out the pdf documents it finds.&#160; The one thing I still want to refine is the ability to close out Acrobat.&#160; Right now it closes Acrobat after printing each document only to reopen it again for the next document.&#160; I will look into just closing it at the end one time.&#160; But for now this is at least a decent working script I plan to get a lot of use out of.&#160; </p>
<br />Filed under: <a href='https://gregcaporale.wordpress.com/category/powershell/'>PowerShell</a>, <a href='https://gregcaporale.wordpress.com/category/system-admin/windows-server/'>Windows Server</a> Tagged: <a href='https://gregcaporale.wordpress.com/tag/acrobat/'>acrobat</a>, <a href='https://gregcaporale.wordpress.com/tag/powershell-2/'>Powershell</a>, <a href='https://gregcaporale.wordpress.com/tag/printing/'>printing</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporale.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporale.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporale.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporale.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregcaporale.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregcaporale.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregcaporale.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregcaporale.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporale.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporale.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporale.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporale.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporale.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporale.wordpress.com/88/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=88&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gregcaporale.wordpress.com/2012/01/23/updated-powershell-script-to-loop-through-files-for-printing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/dea0839821c850747cf92f7fa87e09e0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">gregcaporale</media:title>
		</media:content>
	</item>
		<item>
		<title>Using PowerShell to print pdf files automatically</title>
		<link>https://gregcaporale.wordpress.com/2012/01/18/powershell-to-print-files-automatically/</link>
		<comments>https://gregcaporale.wordpress.com/2012/01/18/powershell-to-print-files-automatically/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 20:50:00 +0000</pubDate>
		<dc:creator>gregcaporale</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[printing]]></category>

		<guid isPermaLink="false">https://gregcaporale.wordpress.com/?p=76</guid>
		<description><![CDATA[My office has a series of nightly reports from SQL Server that export as Adobe documents.  The users want them printed and waiting for them each morning on a specific printer.  We had a little utility that could do this (and more) but the problem with it was that the computer running the utility had [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=76&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My office has a series of nightly reports from SQL Server that export as Adobe documents.  The users want them printed and waiting for them each morning on a specific printer.  We had a little utility that could do this (and more) but the problem with it was that the computer running the utility had to be logged in and the utility had to be launched.  Occasionally we would run into issues where the computer was rebooted and as a result the reports would not be printed out in the morning.</p>
<p>So, that got me to thinking.  This would be a great way to use PowerShell!  So here is what I did.</p>
<p>First I started experimenting with the Out-Printer cmdlet to see if I could use that.  However since a pdf document is not plain text I couldn’t use this command.</p>
<p><span style="color:#0000ff;">get-content</span> <span style="color:#c0504d;">c:\docstoprint\doc1.pdf</span> | <span style="color:#0000ff;">Out-Printer</span></p>
<p>All that would get me is several pages worth of useless garbage.</p>
<p>Then I found another command I could use.</p>
<p><span style="color:#0000ff;">Start-Process</span> <span style="color:#0000ff;">–FilePath</span> <span style="color:#c0504d;">“c:\docstoprint\doc1.pdf”</span> <span style="color:#0000ff;">–Verb</span> <span style="color:#c0504d;">Print</span></p>
<p>This worked exactly like I had hoped.  I was able to print the pdf document to my default printer.  With one side effect, Adobe was left open after the print job.  So I tried this option.</p>
<p><span style="color:#0000ff;">Start-Process</span> <span style="color:#0000ff;">–FilePath</span> <span style="color:#c0504d;">“c:\docstoprint\doc1.pdf”</span> <span style="color:#0000ff;">–Verb</span> <span style="color:#c0504d;">Print</span> <span style="color:#0000ff;">-PassThru</span> | <span style="color:#0000ff;">%</span>{<span style="color:#0000ff;">sleep</span> 10;$_} | <span style="color:#0000ff;">kill</span></p>
<p>The extra options told powershell to wait 10 seconds and then kill the process.  This worked perfectly.  So now all I needed to do was create a script to print out the list of documents and then set it up in Task Scheduler.</p>
<p>So here is my finished script.<br />
<span style="color:#0000ff;">Start-Process</span> <span style="color:#000080;">-FilePath</span> <span style="color:#8b0000;">&#8220;c:\docstoprint\doc1.pdf&#8221;</span> <span style="color:#000080;">–Verb</span> <span style="color:#8a2be2;">Print</span> <span style="color:#000080;">-PassThru</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">%</span><span style="color:#000000;">{</span><span style="color:#0000ff;">sleep</span> <span style="color:#800080;">10</span><span style="color:#000000;">;</span><span style="color:#ff4500;">$_</span><span style="color:#000000;">}</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">kill</span>            </p>
<p><span style="color:#0000ff;">Start-Process</span> <span style="color:#000080;">-FilePath</span> <span style="color:#8b0000;">&#8220;c:\docstoprint\doc2.pdf&#8221;</span> <span style="color:#000080;">–Verb</span> <span style="color:#8a2be2;">Print</span> <span style="color:#000080;">-PassThru</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">%</span><span style="color:#000000;">{</span><span style="color:#0000ff;">sleep</span> <span style="color:#800080;">10</span><span style="color:#000000;">;</span><span style="color:#ff4500;">$_</span><span style="color:#000000;">}</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">kill</span>            </p>
<p><span style="color:#0000ff;">Start-Process</span> <span style="color:#000080;">-FilePath</span> <span style="color:#8b0000;">&#8220;c:\docstoprint\doc3.pdf&#8221;</span> <span style="color:#000080;">–Verb</span> <span style="color:#8a2be2;">Print</span> <span style="color:#000080;">-PassThru</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">%</span><span style="color:#000000;">{</span><span style="color:#0000ff;">sleep</span> <span style="color:#800080;">10</span><span style="color:#000000;">;</span><span style="color:#ff4500;">$_</span><span style="color:#000000;">}</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">kill</span>            </p>
<p><span style="color:#0000ff;">Start-Process</span> <span style="color:#000080;">-FilePath</span> <span style="color:#8b0000;">&#8220;c:\docstoprint\doc4.pdf&#8221;</span> <span style="color:#000080;">–Verb</span> <span style="color:#8a2be2;">Print</span> <span style="color:#000080;">-PassThru</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">%</span><span style="color:#000000;">{</span><span style="color:#0000ff;">sleep</span> <span style="color:#800080;">10</span><span style="color:#000000;">;</span><span style="color:#ff4500;">$_</span><span style="color:#000000;">}</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">kill</span>            </p>
<p><span style="color:#0000ff;">Start-Process</span> <span style="color:#000080;">-FilePath</span> <span style="color:#8b0000;">&#8220;c:\docstoprint\doc5.pdf&#8221;</span> <span style="color:#000080;">–Verb</span> <span style="color:#8a2be2;">Print</span> <span style="color:#000080;">-PassThru</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">%</span><span style="color:#000000;">{</span><span style="color:#0000ff;">sleep</span> <span style="color:#800080;">10</span><span style="color:#000000;">;</span><span style="color:#ff4500;">$_</span><span style="color:#000000;">}</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">kill</span><br />
The last step is to actually schedule this in Windows Task Scheduler.</p>
<p>So, first launch Task Scheduler, right click on the Task Scheduler Library and select “Create Basic Task”</p>
<p><a href="http://gregcaporale.files.wordpress.com/2012/01/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://gregcaporale.files.wordpress.com/2012/01/image_thumb.png?w=363&#038;h=290" alt="image" width="363" height="290" border="0" /></a></p>
<p>&nbsp;</p>
<p>Give your task a meaningful name, I chose “Daily Automated Report Printout”.  And put a little description of the task so someone else will understand the purpose.  Then click Next.</p>
<p>The next step is to decide when you want the task to start.  In my case I need it every weekday at 6am.  So, I chose “Weekly” and then clicked next to select the time and days.   After selecting the days and time click Next.</p>
<p>Now you need to tell Task Scheduler what action you want to perform.  In this case you want to “Start a Program”</p>
<p><a href="http://gregcaporale.files.wordpress.com/2012/01/image1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://gregcaporale.files.wordpress.com/2012/01/image_thumb1.png?w=371&#038;h=275" alt="image" width="371" height="275" border="0" /></a></p>
<p>Click Next and then you need to tell Task Scheduler what program to start.</p>
<p><a href="http://gregcaporale.files.wordpress.com/2012/01/image2.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://gregcaporale.files.wordpress.com/2012/01/image_thumb2.png?w=371&#038;h=275" alt="image" width="371" height="275" border="0" /></a></p>
<p>&nbsp;</p>
<p>The program is powershell.exe and it should be located in <span style="color:#0000ff;">C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</span></p>
<p><span style="color:#000000;">Then in the “Add arguments” section you need to put in the path to the powershell script.  In my case it was </span><span style="color:#0000ff;">c:\users\greg\documents\powershell\DocsToPrint.ps1</span></p>
<p><span style="color:#000000;">Click Next to finish the wizard.  You will be presented with a Summary of your new task, make sure everything is correct, be sure to click the “Open the Properties dialog” checkbox and then click Finish.    </span></p>
<p><span style="color:#000000;">In the Properties for the task you have one last step to configure.  </span></p>
<p>In the Security Options section on the General Tab, you need to change the option to “Run whether user is logged on or not”</p>
<p><a href="http://gregcaporale.files.wordpress.com/2012/01/image3.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://gregcaporale.files.wordpress.com/2012/01/image_thumb3.png?w=373&#038;h=298" alt="image" width="373" height="298" border="0" /></a></p>
<p>Then when you click OK you will be asked to put in account credentials for running this task.  That way when the job is started it will have privileges to run the job and print out to the default printer.</p>
<br />Filed under: <a href='https://gregcaporale.wordpress.com/category/powershell/'>PowerShell</a>, <a href='https://gregcaporale.wordpress.com/category/system-admin/windows-server/'>Windows Server</a> Tagged: <a href='https://gregcaporale.wordpress.com/tag/automation/'>automation</a>, <a href='https://gregcaporale.wordpress.com/tag/powershell-2/'>Powershell</a>, <a href='https://gregcaporale.wordpress.com/tag/printing/'>printing</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporale.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporale.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporale.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporale.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregcaporale.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregcaporale.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregcaporale.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregcaporale.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporale.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporale.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporale.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporale.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporale.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporale.wordpress.com/76/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=76&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gregcaporale.wordpress.com/2012/01/18/powershell-to-print-files-automatically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/dea0839821c850747cf92f7fa87e09e0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">gregcaporale</media:title>
		</media:content>

		<media:content url="http://gregcaporale.files.wordpress.com/2012/01/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://gregcaporale.files.wordpress.com/2012/01/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://gregcaporale.files.wordpress.com/2012/01/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://gregcaporale.files.wordpress.com/2012/01/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Get Quarter begin and end dates</title>
		<link>https://gregcaporale.wordpress.com/2012/01/15/get-quarter-begin-and-end-dates/</link>
		<comments>https://gregcaporale.wordpress.com/2012/01/15/get-quarter-begin-and-end-dates/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 00:11:11 +0000</pubDate>
		<dc:creator>gregcaporale</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://gregcaporale.wordpress.com/?p=64</guid>
		<description><![CDATA[This is a script I wrote to use when I need to get the quarter begin and end dates for SQL. declare&#160;@date&#160;datetime declare&#160;@begdate&#160;datetime declare&#160;@enddate&#160;datetime set&#160;@date&#160;=&#160;getdate() &#045;&#045;get&#160;first&#160;day&#160;of&#160;CURRENT&#160;qtr&#160; set&#160;@begdate&#160;=&#160;dateadd(q,&#160;datediff(q,&#160;0,&#160;@date),&#160;0) &#045;&#045;get&#160;last&#160;day&#160;of&#160;CURRENT&#160;qtr&#160; set&#160;@enddate&#160;=&#160;dateadd(q,&#160;datediff(q,&#160;0,&#160;dateadd(q,&#160;1,&#160;@date)),&#160;-1) select&#160;@date&#160;as&#160;today,&#160;@begdate&#160;as&#160;QtrBegin,&#160;@enddate&#160;as&#160;QtrEnd Filed under: SQL Server Tagged: sql, SQL Server<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=64&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is a script I wrote to use when I need to get the quarter begin and end dates for SQL.  </p>
<p><code>
<div><span style="font-family:Courier New;font-size:10pt;"><br />
<font color="blue">declare</font>&nbsp;<font color="#8000FF">@date</font>&nbsp;<font color="black"><i>datetime</i></font><br />
<br /><font color="blue">declare</font>&nbsp;<font color="#8000FF">@begdate</font>&nbsp;<font color="black"><i>datetime</i></font><br />
<br /><font color="blue">declare</font>&nbsp;<font color="#8000FF">@enddate</font>&nbsp;<font color="black"><i>datetime</i></font></p>
<p><font color="blue">set</font>&nbsp;<font color="#8000FF">@date</font>&nbsp;<font color="silver">=</font>&nbsp;<font color="fuchsia"><i>getdate</i></font><font color="maroon">(</font><font color="maroon">)</font><br />
<br /><font color="green"><i>&#045;&#045;get&nbsp;first&nbsp;day&nbsp;of&nbsp;CURRENT&nbsp;qtr&nbsp;</i></font><br />
<br /><font color="blue">set</font>&nbsp;<font color="#8000FF">@begdate</font>&nbsp;<font color="silver">=</font>&nbsp;<font color="fuchsia"><i>dateadd</i></font><font color="maroon">(</font><font color="maroon">q</font><font color="silver">,</font>&nbsp;<font color="fuchsia"><i>datediff</i></font><font color="maroon">(</font><font color="maroon">q</font><font color="silver">,</font>&nbsp;<font color="black">0</font><font color="silver">,</font>&nbsp;<font color="#8000FF">@date</font><font color="maroon">)</font><font color="silver">,</font>&nbsp;<font color="black">0</font><font color="maroon">)</font></p>
<p><font color="green"><i>&#045;&#045;get&nbsp;last&nbsp;day&nbsp;of&nbsp;CURRENT&nbsp;qtr&nbsp;</i></font><br />
<br /><font color="blue">set</font>&nbsp;<font color="#8000FF">@enddate</font>&nbsp;<font color="silver">=</font>&nbsp;<font color="fuchsia"><i>dateadd</i></font><font color="maroon">(</font><font color="maroon">q</font><font color="silver">,</font>&nbsp;<font color="fuchsia"><i>datediff</i></font><font color="maroon">(</font><font color="maroon">q</font><font color="silver">,</font>&nbsp;<font color="black">0</font><font color="silver">,</font>&nbsp;<font color="fuchsia"><i>dateadd</i></font><font color="maroon">(</font><font color="maroon">q</font><font color="silver">,</font>&nbsp;<font color="black">1</font><font color="silver">,</font>&nbsp;<font color="#8000FF">@date</font><font color="maroon">)</font><font color="maroon">)</font><font color="silver">,</font>&nbsp;<font color="silver">-</font><font color="black">1</font><font color="maroon">)</font></p>
<p><font color="blue">select</font>&nbsp;<font color="#8000FF">@date</font>&nbsp;<font color="blue">as</font>&nbsp;<font color="maroon">today</font><font color="silver">,</font>&nbsp;<font color="#8000FF">@begdate</font>&nbsp;<font color="blue">as</font>&nbsp;<font color="maroon">QtrBegin</font><font color="silver">,</font>&nbsp;<font color="#8000FF">@enddate</font>&nbsp;<font color="blue">as</font>&nbsp;<font color="maroon">QtrEnd</font><br />
<br />
</span></div>
<p></code></p>
<br />Filed under: <a href='https://gregcaporale.wordpress.com/category/system-admin/sql-server/'>SQL Server</a> Tagged: <a href='https://gregcaporale.wordpress.com/tag/sql/'>sql</a>, <a href='https://gregcaporale.wordpress.com/tag/sql-server/'>SQL Server</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporale.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporale.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporale.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporale.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregcaporale.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregcaporale.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregcaporale.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregcaporale.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporale.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporale.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporale.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporale.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporale.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporale.wordpress.com/64/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=64&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gregcaporale.wordpress.com/2012/01/15/get-quarter-begin-and-end-dates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/dea0839821c850747cf92f7fa87e09e0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">gregcaporale</media:title>
		</media:content>
	</item>
		<item>
		<title>Running Subscriptions</title>
		<link>https://gregcaporale.wordpress.com/2012/01/15/running-subscriptions/</link>
		<comments>https://gregcaporale.wordpress.com/2012/01/15/running-subscriptions/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 23:00:56 +0000</pubDate>
		<dc:creator>gregcaporale</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[query]]></category>

		<guid isPermaLink="false">http://gregcaporale.wordpress.com/?p=53</guid>
		<description><![CDATA[Once you have kicked off your report subscription you might want to see the status. Again, if you don&#8217;t want to log onto the SQL Server Reporting Services web interface you can do this with a simple SQL Query. /*Active (Running) subscriptions*/ SELECT c.name, rs.scheduleid AS jobid, sub.DESCRIPTION, sub.laststatus FROM reportserver..catalog c INNER JOIN reportserver..subscriptions subON (c.itemid = sub.report_oid) INNER JOIN reportserver..activesubscriptions asubON (sub.subscriptionid = asub.subscriptionid) INNER JOIN reportserver..reportschedule rsON (sub.subscriptionid = rs.subscriptionid) This query will return the Report [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=53&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Once you have kicked off your report subscription you might want to see the status. Again, if you don&#8217;t want to log onto the SQL Server Reporting Services web interface you can do this with a simple SQL Query.</p>
<div><span style="font-family:Courier New;font-size:10pt;"><br />
<span style="color:green;"><em>/*Active (Running) subscriptions*/</em></span></p>
<p><span style="color:blue;">SELECT</span></p>
<p><span style="color:maroon;">c</span><span style="color:silver;">.</span><span style="color:maroon;">name</span><span style="color:silver;">,</span></p>
<p><span style="color:maroon;">rs</span><span style="color:silver;">.</span><span style="color:maroon;">scheduleid</span> <span style="color:blue;">AS</span> <span style="color:maroon;">jobid</span><span style="color:silver;">,</span></p>
<p><span style="color:maroon;">sub</span><span style="color:silver;">.</span><span style="color:blue;">DESCRIPTION</span><span style="color:silver;">,</span></p>
<p><span style="color:maroon;">sub</span><span style="color:silver;">.</span><span style="color:maroon;">laststatus</span></p>
<p><span style="color:blue;">FROM</span> <span style="color:maroon;">reportserver</span><span style="color:silver;">.</span><span style="color:silver;">.</span><span style="color:maroon;">catalog</span> <span style="color:maroon;">c</span></p>
<p><span style="color:blue;">INNER</span> <span style="color:blue;">JOIN</span> <span style="color:maroon;">reportserver</span><span style="color:silver;">.</span><span style="color:silver;">.</span><span style="color:maroon;">subscriptions</span> <span style="color:maroon;">sub</span><br /><span style="color:blue;">ON</span> <span style="color:maroon;">(</span><span style="color:maroon;">c</span><span style="color:silver;">.</span><span style="color:maroon;">itemid</span> <span style="color:silver;">=</span> <span style="color:maroon;">sub</span><span style="color:silver;">.</span><span style="color:maroon;">report_oid</span><span style="color:maroon;">)</span></p>
<p><span style="color:blue;">INNER</span> <span style="color:blue;">JOIN</span> <span style="color:maroon;">reportserver</span><span style="color:silver;">.</span><span style="color:silver;">.</span><span style="color:maroon;">activesubscriptions</span> <span style="color:maroon;">asub</span><br /><span style="color:blue;">ON</span> <span style="color:maroon;">(</span><span style="color:maroon;">sub</span><span style="color:silver;">.</span><span style="color:maroon;">subscriptionid</span> <span style="color:silver;">=</span> <span style="color:maroon;">asub</span><span style="color:silver;">.</span><span style="color:maroon;">subscriptionid</span><span style="color:maroon;">)</span></p>
<p><span style="color:blue;">INNER</span> <span style="color:blue;">JOIN</span> <span style="color:maroon;">reportserver</span><span style="color:silver;">.</span><span style="color:silver;">.</span><span style="color:maroon;">reportschedule</span> <span style="color:maroon;">rs</span><br /><span style="color:blue;">ON</span> <span style="color:maroon;">(</span><span style="color:maroon;">sub</span><span style="color:silver;">.</span><span style="color:maroon;">subscriptionid</span> <span style="color:silver;">=</span> <span style="color:maroon;">rs</span><span style="color:silver;">.</span><span style="color:maroon;">subscriptionid</span><span style="color:maroon;">)</span></p>
<p></span></div>
<p>This query will return the Report Name, the JobID, description and the LastStatus.</p>
<br />Filed under: <a href='https://gregcaporale.wordpress.com/category/system-admin/sql-server/reporting-services/'>Reporting Services</a>, <a href='https://gregcaporale.wordpress.com/category/system-admin/sql-server/'>SQL Server</a> Tagged: <a href='https://gregcaporale.wordpress.com/tag/query/'>query</a>, <a href='https://gregcaporale.wordpress.com/tag/reporting-services/'>Reporting Services</a>, <a href='https://gregcaporale.wordpress.com/tag/sql-server/'>SQL Server</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporale.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporale.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporale.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporale.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregcaporale.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregcaporale.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregcaporale.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregcaporale.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporale.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporale.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporale.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporale.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporale.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporale.wordpress.com/53/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=53&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gregcaporale.wordpress.com/2012/01/15/running-subscriptions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/dea0839821c850747cf92f7fa87e09e0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">gregcaporale</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the Job ID to rerun a subscription</title>
		<link>https://gregcaporale.wordpress.com/2012/01/15/using-the-job-id-to-rerun-a-subscription/</link>
		<comments>https://gregcaporale.wordpress.com/2012/01/15/using-the-job-id-to-rerun-a-subscription/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 22:47:44 +0000</pubDate>
		<dc:creator>gregcaporale</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[Reporting Services]]></category>

		<guid isPermaLink="false">http://gregcaporale.wordpress.com/?p=45</guid>
		<description><![CDATA[The previous post showed a sql script that is useful for finding all your Reporting Services jobs. Now that you have that information, lets say you&#8217;d like to kick off a scheduled report that either already ran, or you&#8217;d like to run again but you don&#8217;t want to have to step through all the settings [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=45&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The previous post showed a sql script that is useful for finding all your Reporting Services jobs.  Now that you have that information, lets say you&#8217;d like to kick off a scheduled report that either already ran, or you&#8217;d like to run again but you don&#8217;t want to have to step through all the settings for that subscription in the Reporting Services web interface.  Instead you can use the Job ID that you got in the previous result set and use it to start the report job.  I use this script every month to manually kick off a scheduled report that generates client invoices.  </p>
<div><span style="font-family:Courier New;font-size:10pt;"><br />
<font color="green"><i>/*&nbsp;&nbsp;Report&nbsp;Server&nbsp;Rerun&nbsp;subscription&nbsp;&nbsp;*/</i></font></p>
<p><font color="green"><i>&#045;&#045;Execute&nbsp;Monthly&nbsp;Web&nbsp;Statement&nbsp;Subscripion</i></font><br />
<br /><font color="blue">EXEC</font>&nbsp;<font color="maroon">msdb</font><font color="silver">.</font><font color="silver">.</font><font color="#FF0080"><b>Sp_start_job</b></font>&nbsp;<font color="#8000FF">@job_name</font>&nbsp;<font color="silver">=</font>&nbsp;<font color="red">&#8216;A251BE76-0453-4A8F-8C98-69439B881B23&#8242;</font><br />
<br /><font color="green"><i>&#045;&#045;Client&nbsp;Holdings</i></font><br />
<br /><font color="blue">EXEC</font>&nbsp;<font color="maroon">msdb</font><font color="silver">.</font><font color="silver">.</font><font color="#FF0080"><b>Sp_start_job</b></font>&nbsp;<font color="#8000FF">@job_name</font>&nbsp;<font color="silver">=</font>&nbsp;<font color="red">&#8217;57AD46EF-A46F-41A7-83F3-9430B51CEDE8&#8242;</font><br />
<br /><font color="green"><i>&#045;&#045;Standard&nbsp;subscription</i></font><br />
<br /><font color="blue">EXEC</font>&nbsp;<font color="maroon">msdb</font><font color="silver">.</font><font color="silver">.</font><font color="#FF0080"><b>Sp_start_job</b></font>&nbsp;<font color="#8000FF">@job_name</font>&nbsp;<font color="silver">=</font>&nbsp;<font color="red">&#8216;DC1C9E50-D18E-4A69-9452-2274D21232D7&#8242;</font><br />
<br />
</span></div>
<br />Filed under: <a href='https://gregcaporale.wordpress.com/category/system-admin/sql-server/'>SQL Server</a> Tagged: <a href='https://gregcaporale.wordpress.com/tag/query/'>query</a>, <a href='https://gregcaporale.wordpress.com/tag/reporting-services/'>Reporting Services</a>, <a href='https://gregcaporale.wordpress.com/tag/sql-server/'>SQL Server</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporale.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporale.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporale.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporale.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gregcaporale.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gregcaporale.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gregcaporale.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gregcaporale.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporale.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporale.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporale.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporale.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporale.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporale.wordpress.com/45/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gregcaporale.wordpress.com&amp;blog=31386537&amp;post=45&amp;subd=gregcaporale&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gregcaporale.wordpress.com/2012/01/15/using-the-job-id-to-rerun-a-subscription/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/dea0839821c850747cf92f7fa87e09e0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">gregcaporale</media:title>
		</media:content>
	</item>
	</channel>
</rss>
