<?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>Personal Weblog of John Wood &#187; .Net</title>
	<atom:link href="http://www.webofwood.com/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webofwood.com</link>
	<description>Wordpress weblog of John Wood, a Database Administrator</description>
	<lastBuildDate>Thu, 29 Jul 2010 14:00:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Cycle Those SQL Server Logs</title>
		<link>http://www.webofwood.com/2010/02/15/cycle-those-sql-server-logs/</link>
		<comments>http://www.webofwood.com/2010/02/15/cycle-those-sql-server-logs/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 21:21:04 +0000</pubDate>
		<dc:creator>John Wood</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[errorlog]]></category>
		<category><![CDATA[schedule]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.webofwood.com/?p=62</guid>
		<description><![CDATA[Don’t you just hate it when you open one of your server logs in Management Studio and then you have to wait forever to review it because it never stops reading? I’ve done it enough times and decided to put an end to it or at least greatly reduce the incidence. Using Powershell and a [...]]]></description>
			<content:encoded><![CDATA[<p>Don’t you just hate it when you open one of your server logs in Management Studio and then you have to wait forever to review it because it never stops reading? I’ve done it enough times and decided to put an end to it or at least greatly reduce the incidence.</p>
<p>Using Powershell and a simple script to execute Sp_Cycle_Errorlog, I now have a weekly, Windows scheduled task which executes the sproc to cycle the logs for all my SQL Servers.</p>
<pre class="brush: ps">foreach ($svr in get-content D:\Scripts\Servers.TXT ){
    $svr
    Invoke-Expression 'SQLCMD -E -S $svr -Q "Exec Sp_Cycle_Errorlog"' | Out-Null
	}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.webofwood.com/2010/02/15/cycle-those-sql-server-logs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Where Clause &#8211; Compare to a list of values</title>
		<link>http://www.webofwood.com/2009/08/04/powershell-where-compare-list/</link>
		<comments>http://www.webofwood.com/2009/08/04/powershell-where-compare-list/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 17:28:35 +0000</pubDate>
		<dc:creator>Woody</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.webofwood.com/2009/08/04/powershell-where-clause-compare-to-a-list-of-values/</guid>
		<description><![CDATA[As a databases admin with a few dozen servers and a few hundred SQL Server database, I need to effectively build automated jobs to perform various administrative tasks such as backing up databases. I&#8217;m still new to PowerShell but I am beginning to see how immensely helpful it is to me and my work. I [...]]]></description>
			<content:encoded><![CDATA[<p>As a databases admin with a few dozen servers and a few hundred SQL Server database, I need to effectively build automated jobs to perform various administrative tasks such as backing up databases. I&#8217;m still new to PowerShell but I am beginning to see how immensely helpful it is to me and my work.</p>
<p>I found a good PowerShell script for backing up databases at <a title="Use Powershel to back up all user databases" href="http://blogs.msdn.com/buckwoody/archive/2009/06/25/use-powershell-to-backup-all-user-databases.aspx" target="_blank">this blog location</a>. However, I wanted to change it slightly to accommodate backing up ALL, System, User, or a list of databases. Processing ALL, System, or User is straightforward enough but I had to it was the first time I came up against have to compare a value against a list of values. In SQL you simply use an IN operator with a list of values but I was not sure of how to accomplish the same process in PowerShell.</p>
<p>Here was my problem: the user could supply a list of databases to backup and the backup script has a line with captures all the database objects for that SQL Server instance. I need to backup only those which are in the users list.</p>
<p>I found that the PowerShell <strong>WHERE</strong> clause can use a <strong>-contains</strong> operator which effectively filters the selection for an array. To test the operation I set up a small script to build two arrays and then I piped one array through a WHERE filter of which the results are piped to a ForEach. The ForEach sees only the results of the WHERE which mimics the SQL IN operator.</p>
<p>Run this code in PowerShell to see what I mean.</p>
<pre class="brush: ps">$a = @("db1","db2","db3","db4")
$d = @("db1","db2","db3","db4","db5","db6","db7","db8")
$d | where { $a -contains $_ } | foreach { Write-Host $_ }</pre>
<p><strong>$a</strong> represents the list of database supplied by the user.<br />
<strong>$d</strong> represents the array of databases returned when accessing the Microsoft.SqlServer.Management.Smo.Server object.<br />
I can now back up the user supplied databases within the foreach script block.</p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:d05e848e-d526-4494-8d76-eea0b3f11e9c" class="wlWriterSmartContent" style="margin: 0px; display: inline; padding: 0px;">del.icio.us Tags: <a rel="tag" href="http://del.icio.us/popular/PowerShell%20Script%20Where%20compare%20list">PowerShell Script Where compare list</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.webofwood.com/2009/08/04/powershell-where-compare-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tips &amp; Tricks Using Compare-Object &#8211; Copy New Files</title>
		<link>http://www.webofwood.com/2009/07/29/tips-tricks-using-compare-object-copy-new-files/</link>
		<comments>http://www.webofwood.com/2009/07/29/tips-tricks-using-compare-object-copy-new-files/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 15:57:32 +0000</pubDate>
		<dc:creator>Woody</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[compare]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.webofwood.com/2009/07/29/tips-tricks-using-compare-object-copy-new-files/</guid>
		<description><![CDATA[This is a wonderful article which not only details the use of Compare-Object but also provides some very excellent examples on its use. Tips &#38; Tricks Using Compare-Object &#8211; Dreaming in PowerShell &#8211; PowerShell.com I am very new to PowerShell but I am beginning to like using it considerably more each day. I recently had [...]]]></description>
			<content:encoded><![CDATA[<p>This is a wonderful article which not only details the use of Compare-Object but also provides some very excellent examples on its use.</p>
<p><a href="http://powershell.com/cs/blogs/tobias/archive/2009/01/09/tipps-amp-tricks-using-compare-object.aspx">Tips &amp; Tricks Using Compare-Object &#8211; Dreaming in PowerShell &#8211; PowerShell.com</a></p>
<p>I am very new to PowerShell but I am beginning to like using it considerably more each day. I recently had a need for a quick and easy way to script a process which would copy only new files from one location to another. after scouring the Internet for a good example, I stumbled upon the Compare-Object cmdlet and this <a title="Compare-Object" href="http://powershell.com/cs/blogs/tobias/archive/2009/01/09/tipps-amp-tricks-using-compare-object.aspx" target="_blank">excellent article</a>.</p>
<p>The actual script I came up with is rather simple and serves my purpose exactly. As I  mentioned, I am new to PowerShell and there may very well be a better method. However, this one works for me.</p>
<h3>The script code:</h3>
<pre class="brush: ps">param(
    [string]$s = '\\serverx\c$\ProgramData\Polaris\3.5\SQLVS1\AuthorityUpdates',
    [string]$t = '\\servery\data03\shared\libraries\zmarc'
)

$target = Get-ChildItem $t
$source = get-childitem $s
Compare-Object $source $target -Property Name -PassThru |
    Where-Object { $_.SideIndicator -eq '&lt;=' } |
    foreach-object -process{
        copy-item $_.FullName -destination $t
        }</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.webofwood.com/2009/07/29/tips-tricks-using-compare-object-copy-new-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Darn, I was really hoping I wouldn&#8217;t have to re-install .NET 2003</title>
		<link>http://www.webofwood.com/2007/02/23/vs-studio-targets-one-version-of-net/</link>
		<comments>http://www.webofwood.com/2007/02/23/vs-studio-targets-one-version-of-net/#comments</comments>
		<pubDate>Fri, 23 Feb 2007 17:57:37 +0000</pubDate>
		<dc:creator>John Wood</dc:creator>
				<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://www.webofwood.com/2007/02/23/darn-i-was-really-hoping-i-wouldnt-have-to-re-install-net-2003/</guid>
		<description><![CDATA[I write very small console apps which run on different servers, some of which cannot yet be upgraded from .NET 1.1 to 2.0. Why Visual Studio targets only one version of the .NET Framework]]></description>
			<content:encoded><![CDATA[<p>I write very small console apps which run on different servers, some of which cannot yet be upgraded from .NET 1.1 to 2.0.</p>
<h2 style="font-weight: normal"><a href="http://blogs.msdn.com/johnri/archive/2005/11/29/498219.aspx"><small>Why Visual Studio targets only one version of the .NET Framework</small></a></h2>
]]></content:encoded>
			<wfw:commentRss>http://www.webofwood.com/2007/02/23/vs-studio-targets-one-version-of-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
