<?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>youdidwhatwithtsql.com &#187; Powershell</title>
	<atom:link href="http://www.youdidwhatwithtsql.com/category/powershell/feed" rel="self" type="application/rss+xml" />
	<link>http://www.youdidwhatwithtsql.com</link>
	<description>making DBAs everywhere curse!</description>
	<lastBuildDate>Tue, 31 Jan 2012 12:21:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Check Mirroring Status with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/check-mirroring-status-powershell/1436</link>
		<comments>http://www.youdidwhatwithtsql.com/check-mirroring-status-powershell/1436#comments</comments>
		<pubDate>Tue, 31 Jan 2012 12:21:23 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[mirroring]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1436</guid>
		<description><![CDATA[Here&#8217;s a simple Powershell snippet to check the mirroring status on your SQL Server instances. ?View Code POWERSHELL# Load SMO extension &#91;System.Reflection.Assembly&#93;::LoadWithPartialName&#40;&#34;Microsoft.SqlServer.Smo&#34;&#41; &#124; Out-Null; &#160; # Servers to check $sqlservers = @&#40;&#34;server1&#34;, &#34;server2&#34;, &#34;server3&#34;&#41;; foreach&#40;$server in $sqlservers&#41; &#123; $srv = New-Object &#34;Microsoft.SqlServer.Management.Smo.Server&#34; $server; # Get mirrored databases $databases = $srv.Databases &#124; Where-Object &#123;$_.IsMirroringEnabled -eq $true&#125;; Write-Host [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/check-mirroring-status-powershell/1436">Check Mirroring Status with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple <a title="Windows Powershell" href="http://technet.microsoft.com/en-us/scriptcenter/dd742419" target="_blank">Powershell</a> snippet to check the <a title="SQL Server Mirroring Status" href="http://msdn.microsoft.com/en-us/library/ms365781.aspx" target="_blank">mirroring status</a> on your SQL Server instances.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1436code2'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14362"><td class="code" id="p1436code2"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Load SMO extension</span>
<span style="color: #000000;">&#91;</span><span style="color: #008080;">System.Reflection.Assembly</span><span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.SqlServer.Smo&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span>;
&nbsp;
<span style="color: #008000;"># Servers to check</span>
<span style="color: #800080;">$sqlservers</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;server1&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;server2&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;server3&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$server</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$sqlservers</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$srv</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #800000;">&quot;Microsoft.SqlServer.Management.Smo.Server&quot;</span> <span style="color: #800080;">$server</span>;
	<span style="color: #008000;"># Get mirrored databases</span>
	<span style="color: #800080;">$databases</span> <span style="color: pink;">=</span> <span style="color: #800080;">$srv</span>.Databases <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Where-Object</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.IsMirroringEnabled <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#125;</span>; 
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800080;">$server</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;==================================&quot;</span>;
	<span style="color: #800080;">$databases</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> <span style="color: #008080; font-style: italic;">-Property</span> Name<span style="color: pink;">,</span> MirroringStatus <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-Table</span> <span style="color: #008080; font-style: italic;">-AutoSize</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>This will output something looking like below&#8230;</p>
<pre>server1
====================================

Name                 MirroringStatus
----                 ---------------
db1         		Synchronized
db2                    	Synchronized
db3              	Synchronized
db4			Synchronized
db5    			Synchronized
server2
=====================================

Name                 MirroringStatus
----                 ---------------
db1         		Synchronized
db2                    	Synchronized
db3              	Synchronized
db4			Synchronized
db5    			Synchronized
server3
=====================================

Name                 MirroringStatus
----                 ---------------
db1         		Synchronized
db2                    	Synchronized
db3              	Synchronized
db4			Synchronized
db5    			Synchronized</pre>
<p><map name='google_ad_map_1436_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1436?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1436_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1436&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fcheck-mirroring-status-powershell%2F1436' title="Check Mirroring Status with Powershell" alt=" Check Mirroring Status with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/check-mirroring-status-powershell/1436">Check Mirroring Status with Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/check-mirroring-status-powershell/1436" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/check-mirroring-status-powershell/1436/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get-ServerErrors Powershell Function</title>
		<link>http://www.youdidwhatwithtsql.com/getservererrors-powershell-function/1431</link>
		<comments>http://www.youdidwhatwithtsql.com/getservererrors-powershell-function/1431#comments</comments>
		<pubDate>Fri, 06 Jan 2012 16:57:26 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1431</guid>
		<description><![CDATA[Here&#8217;s a little Powershell function I&#8217;m using to check the Event Logs and SQL Server Error Logs in one easy swoop; ?View Code POWERSHELLfunction Get-ServerErrors &#123; # Server to check &#38;amp; hours back. Will only support default sql instances # Could add a third param for instance and modify script where appropriate if needed param &#40;$server, [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/getservererrors-powershell-function/1431">Get-ServerErrors Powershell Function</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little Powershell function I&#8217;m using to check the <a title="Windows Event Logs" href="http://technet.microsoft.com/en-us/library/cc722404.aspx" target="_blank">Event Logs</a> and <a title="SQL server Error Logs" href="http://sqlserverpedia.com/wiki/SQL_Server_Error_Logs" target="_blank">SQL Server Error Logs</a> in one easy swoop;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1431code5'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14315"><td class="code" id="p1431code5"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">function</span> Get<span style="color: pink;">-</span>ServerErrors
<span style="color: #000000;">&#123;</span>
	<span style="color: #008000;"># Server to check &amp;amp; hours back. Will only support default sql instances</span>
	<span style="color: #008000;"># Could add a third param for instance and modify script where appropriate if needed</span>
	<span style="color: #0000FF;">param</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$server</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$hours</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #000000;">&#91;</span>datetime<span style="color: #000000;">&#93;</span><span style="color: #800080;">$after</span> <span style="color: pink;">=</span> $<span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span>.AddHours<span style="color: #000000;">&#40;</span><span style="color: pink;">-</span><span style="color: #800080;">$hours</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #008000;"># Windows Event Log (Application &amp;amp; System) Errors &amp;amp; Warnings</span>
&nbsp;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Application Event Log Errors from $server after $after&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;========================================================================&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Get-EventLog</span> <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$server</span> <span style="color: #008080; font-style: italic;">-LogName</span> <span style="color: #800000;">&quot;Application&quot;</span> <span style="color: pink;">-</span>EntryType <span style="color: #800000;">&quot;Error&quot;</span> <span style="color: pink;">-</span>After <span style="color: #800080;">$after</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Press any key to continue or ctrl + c to quit&quot;</span>;
	<span style="color: #800080;">$r</span> <span style="color: pink;">=</span> <span style="color: #800080;">$host</span>.UI.RawUI.ReadKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;NoEcho,IncludeKeyDown&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;System Event Log Errors from $server after $after&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;========================================================================&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Get-EventLog</span> <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$server</span> <span style="color: #008080; font-style: italic;">-LogName</span> <span style="color: #800000;">&quot;System&quot;</span> <span style="color: pink;">-</span>EntryType <span style="color: #800000;">&quot;Error&quot;</span> <span style="color: pink;">-</span>After <span style="color: #800080;">$after</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Press any key to continue or ctrl + c to quit&quot;</span>;
	<span style="color: #800080;">$r</span> <span style="color: pink;">=</span> <span style="color: #800080;">$host</span>.UI.RawUI.ReadKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;NoEcho,IncludeKeyDown&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Application Event Log Warnings from $server after $after&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;========================================================================&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Get-EventLog</span> <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$server</span> <span style="color: #008080; font-style: italic;">-LogName</span> <span style="color: #800000;">&quot;Application&quot;</span> <span style="color: pink;">-</span>EntryType <span style="color: #800000;">&quot;Warning&quot;</span> <span style="color: pink;">-</span>After <span style="color: #800080;">$after</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Press any key to continue or ctrl + c to quit&quot;</span>;
	<span style="color: #800080;">$r</span> <span style="color: pink;">=</span> <span style="color: #800080;">$host</span>.UI.RawUI.ReadKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;NoEcho,IncludeKeyDown&quot;</span><span style="color: #000000;">&#41;</span>;	
&nbsp;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;System Event Log Warnings from $server after $after&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;========================================================================&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Get-EventLog</span> <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$server</span> <span style="color: #008080; font-style: italic;">-LogName</span> <span style="color: #800000;">&quot;System&quot;</span> <span style="color: pink;">-</span>EntryType <span style="color: #800000;">&quot;Warning&quot;</span> <span style="color: pink;">-</span>After <span style="color: #800080;">$after</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Press any key to continue or ctrl + c to quit&quot;</span>;
	<span style="color: #800080;">$r</span> <span style="color: pink;">=</span> <span style="color: #800080;">$host</span>.UI.RawUI.ReadKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;NoEcho,IncludeKeyDown&quot;</span><span style="color: #000000;">&#41;</span>;	
&nbsp;
	<span style="color: #008000;"># SQL Server Error Log</span>
	<span style="color: #000000;">&#91;</span>reflection.assembly<span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.SqlServer.Smo&quot;</span><span style="color: #000000;">&#41;</span> ;
	<span style="color: #800080;">$sql_server</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> <span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.SqlServer.Management.Smo.Server&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #800080;">$server</span>;
	<span style="color: #800080;">$sql_server</span>.ReadErrorLog<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Where-Object</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Text <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;Error*&quot;</span> <span style="color: #FF0000;">-and</span> <span style="color: #000080;">$_</span>.LogDate <span style="color: #FF0000;">-ge</span> <span style="color: #800080;">$after</span><span style="color: #000000;">&#125;</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Usage is as follows;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1431code6'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14316"><td class="code" id="p1431code6"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>ServerErrors <span style="color: pink;">&lt;</span>server name<span style="color: pink;">&gt;</span> <span style="color: pink;">&lt;</span>hours back to check<span style="color: pink;">&gt;</span>;</pre></td></tr></table></div>

<p><map name='google_ad_map_1431_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1431?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1431_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1431&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fgetservererrors-powershell-function%2F1431' title="Get ServerErrors Powershell Function" alt=" Get ServerErrors Powershell Function" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/getservererrors-powershell-function/1431">Get-ServerErrors Powershell Function</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/getservererrors-powershell-function/1431" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/getservererrors-powershell-function/1431/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>List AD Organizational Units with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/list-ad-organizational-units-powershell/1424</link>
		<comments>http://www.youdidwhatwithtsql.com/list-ad-organizational-units-powershell/1424#comments</comments>
		<pubDate>Fri, 30 Dec 2011 12:28:03 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1424</guid>
		<description><![CDATA[Here&#8217;s a quick Powershell one-liner to list all the Organizational Units, or OUs, in your Active Directory domain. Firstly you&#8217;ll probably need to load the ActiveDirectory module. This can be done at the Powershell prompt with the below command; ?View Code POWERSHELLImport-Module ActiveDirectory; Then we can use the Get-ADOrganizationalUnit cmdlet to retrieve a list of [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/list-ad-organizational-units-powershell/1424">List AD Organizational Units with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick <a title="Windows Powershell" href="http://technet.microsoft.com/en-us/scriptcenter/dd742419">Powershell</a> one-liner to list all the <a title="Active Directory Organizational Unit" href="http://technet.microsoft.com/en-us/library/cc758565%28WS.10%29.aspx" target="_blank">Organizational Units</a>, or OUs, in your Active Directory domain. Firstly you&#8217;ll probably need to load the <a title="Powershell ActiveDirectory Module" href="http://technet.microsoft.com/en-us/library/ee617195.aspx" target="_blank">ActiveDirectory</a> module. This can be done at the Powershell prompt with the below command;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1424code9'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14249"><td class="code" id="p1424code9"><pre class="powershell" style="font-family:monospace;">Import<span style="color: pink;">-</span>Module ActiveDirectory;</pre></td></tr></table></div>

<p>Then we can use the <a title="Get-ADOrganizationalUnit Powershell cmdlet" href="http://technet.microsoft.com/en-us/library/ee617236.aspx" target="_blank">Get-ADOrganizationalUnit cmdlet </a>to retrieve a list of OUs.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1424code10'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p142410"><td class="code" id="p1424code10"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>ADOrganizationalUnit <span style="color: pink;">-</span><span style="color: #0000FF;">Filter</span> <span style="color: pink;">*</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> <span style="color: #008080; font-style: italic;">-Property</span> Name <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-Table</span> <span style="color: #008080; font-style: italic;">-AutoSize</span>;</pre></td></tr></table></div>

<p>This will display a list looking something like below;</p>
<pre>Name
----
Domain Controllers
Microsoft Exchange Security Groups
Security Groups
Domain Servers
Domain Workstations
Domain Guest Accounts
Printers
Management
Virtual Desktops
IT
Service Accounts
Users
Computers
Production Servers
SQL Servers
Web Servers</pre>
<p><map name='google_ad_map_1424_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1424?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1424_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1424&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Flist-ad-organizational-units-powershell%2F1424' title="List AD Organizational Units with Powershell" alt=" List AD Organizational Units with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/list-ad-organizational-units-powershell/1424">List AD Organizational Units with Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/list-ad-organizational-units-powershell/1424" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/list-ad-organizational-units-powershell/1424/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beware the Powershell -Contains operator</title>
		<link>http://www.youdidwhatwithtsql.com/beware-powershell-operator/1403</link>
		<comments>http://www.youdidwhatwithtsql.com/beware-powershell-operator/1403#comments</comments>
		<pubDate>Tue, 29 Nov 2011 12:20:00 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[contains]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/beware-the-powershell-contains-operator/1403</guid>
		<description><![CDATA[Many of us tend to jump quickly, into a new programming or scripting language, applying knowledge we&#8217;ve learned elsewhere to the current task at hand. Broadly speaking this works well but these always a little gotcha to trip you up! A good example is the Powershell -contains operator. It&#8217;s not like .Net String.Contains method as [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/beware-powershell-operator/1403">Beware the Powershell -Contains operator</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Many of us tend to jump quickly, into a new programming or scripting language, applying knowledge we&#8217;ve learned elsewhere to the current task at hand. Broadly speaking this works well but these always a little <a title="Gotcha" href="http://en.wikipedia.org/wiki/Gotcha_(programming)" target="_blank">gotcha</a> to trip you up!</p>
<p>A good example is the Powershell -contains operator. It&#8217;s not like .Net <a title=".Net String.Contains method" href="http://msdn.microsoft.com/en-us/library/dy85x1sa.aspx" target="_blank">String.Contains</a> method as you might first think.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1403code15'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140315"><td class="code" id="p1403code15"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$var</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Rhys Campbell&quot;</span>;
<span style="color: #800080;">$var</span> <span style="color: #FF0000;">-contains</span> <span style="color: #800000;">&quot;Rhys&quot;</span>;</pre></td></tr></table></div>

<p>The result of this is <strong>false</strong>. Why? Because the <strong>-contains</strong> operator in Powershell is used for testing for <a title="Powershell -contains operator" href="http://technet.microsoft.com/en-us/library/ee692798.aspx" target="_blank">items in an array</a>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1403code16'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140316"><td class="code" id="p1403code16"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$var</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Rhys Campbell&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;Joe Bloggs&quot;</span>;
<span style="color: #800080;">$var</span> <span style="color: #FF0000;">-contains</span> <span style="color: #800000;">&quot;Rhys Campbell&quot;</span>;</pre></td></tr></table></div>

<p>Will return <strong>true</strong>, but;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1403code17'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140317"><td class="code" id="p1403code17"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$var</span> <span style="color: #FF0000;">-contains</span> <span style="color: #800000;">&quot;Rhys*&quot;</span>;</pre></td></tr></table></div>

<p>Will return <strong>false</strong> as wildcards will not work as we assume they will. For wildcard matching we can use the <strong>-match</strong> operator.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1403code18'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140318"><td class="code" id="p1403code18"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$var</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Rhys Campbell&quot;</span>;
<span style="color: #800080;">$var</span> <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;Rhys&quot;</span>;</pre></td></tr></table></div>

<p>This will return <strong>true</strong> when matching simple strings or the matching items from an array of strings. Now I&#8217;m going to try and remember what <a href="http://www.youtube.com/watch?v=wg4trPZFUwc" target="_blank">assumption is the mother of</a> (NSFW, contains cussing).</p>
<p><map name='google_ad_map_1403_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1403?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1403_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1403&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fbeware-powershell-operator%2F1403' title="Beware the Powershell  Contains operator" alt=" Beware the Powershell  Contains operator" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/beware-powershell-operator/1403">Beware the Powershell -Contains operator</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/beware-powershell-operator/1403" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/beware-powershell-operator/1403/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Monitoring SSRS Subscriptions with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/monitoring-ssrs-subscriptions-powershell/1392</link>
		<comments>http://www.youdidwhatwithtsql.com/monitoring-ssrs-subscriptions-powershell/1392#comments</comments>
		<pubDate>Fri, 25 Nov 2011 13:17:09 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[SSRS]]></category>
		<category><![CDATA[Report Subscriptions]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1392</guid>
		<description><![CDATA[We don&#8217;t use SSRS much at my workplace but its usage is slowly creeping up. I realised that none of us are keeping an eye on the few subscriptions we have set-up. So I decided to do something about that. Here&#8217;s a bit of Powershell code that uses the SSRS Web Service to pull out [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/monitoring-ssrs-subscriptions-powershell/1392">Monitoring SSRS Subscriptions with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>We don&#8217;t use <a title="SQL Server Reporting Services" href="http://msdn.microsoft.com/en-us/library/ms159106.aspx" target="_blank">SSRS </a>much at my workplace but its usage is slowly creeping up. I realised that none of us are keeping an eye on the few subscriptions we have set-up. So I decided to do something about that.</p>
<p>Here&#8217;s a bit of <a title="Windows Powershell" href="http://technet.microsoft.com/en-us/scriptcenter/dd742419" target="_blank">Powershell</a> code that uses the <a title="SSRS Web Service" href="http://msdn.microsoft.com/en-us/library/ms152787.aspx" target="_blank">SSRS Web Service</a> to pull out a list of subscriptions from SSRS and print out some information to the screen. As always I try to bring problems to attention with a little red text so you can identify any failed subscriptions. There&#8217;s a few assumptions in the script, so be sure to read the comments, and it&#8217;s a far from complete and fully tested script. Just a little something to get me started onto something better.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1392code20'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p139220"><td class="code" id="p1392code20"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># If you use multiple ssrs server just stick in another foreach loop</span>
<span style="color: #008000;"># and iterate over an array of ssrs server names.</span>
<span style="color: #800080;">$reportserver</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;sqlserver&quot;</span>;
<span style="color: #800080;">$url</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;http://$($reportserver)/reportserver/reportservice.asmx?WSDL&quot;</span>;
&nbsp;
<span style="color: #800080;">$ssrs</span> <span style="color: pink;">=</span> New<span style="color: pink;">-</span>WebServiceProxy <span style="color: pink;">-</span>uri <span style="color: #800080;">$url</span> <span style="color: pink;">-</span>UseDefaultCredential <span style="color: #008080; font-style: italic;">-Namespace</span> <span style="color: #800000;">&quot;ReportingWebService&quot;</span>;
&nbsp;
<span style="color: #008000;"># Uncomment to list all available methods &amp;amp; properties in the ssrs web service...</span>
<span style="color: #008000;">#$ssrs | Get-Member;</span>
&nbsp;
<span style="color: #008000;"># Get datasources (assumes default path to folder)</span>
<span style="color: #800080;">$datasources</span> <span style="color: pink;">=</span> <span style="color: #800080;">$ssrs</span>.ListChildren<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;/Data Sources&quot;</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #008000;"># for each datasource</span>
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$ds</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$datasources</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008000;"># Get reports</span>
	<span style="color: #800080;">$reports</span> <span style="color: pink;">=</span> <span style="color: #800080;">$ssrs</span>.ListReportsUsingDataSource<span style="color: #000000;">&#40;</span><span style="color: #800080;">$ds</span>.Path<span style="color: #000000;">&#41;</span>;
	<span style="color: #008000;"># For each report</span>
	<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$r</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$reports</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008000;"># Get all subscriptions</span>
		<span style="color: #800080;">$subscriptions</span> <span style="color: pink;">=</span> <span style="color: #800080;">$ssrs</span>.ListSubscriptions<span style="color: #000000;">&#40;</span><span style="color: #800080;">$r</span>.Path<span style="color: pink;">,</span> <span style="color: #800080;">$r</span>.Owner<span style="color: #000000;">&#41;</span>;
		<span style="color: #008000;"># foreach subscription</span>
		<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$s</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$subscriptions</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #008000;"># Uncomment to view more subscription methods &amp;amp; properties</span>
			<span style="color: #008000;"># $s | Get-Member;</span>
			<span style="color: #008000;"># Probably missing a few important keywords here...</span>
			<span style="color: #800080;">$colour</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Green&quot;</span>;
			<span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$s</span>.Status <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;Failure&quot;</span> <span style="color: #FF0000;">-or</span> <span style="color: #800080;">$s</span>.Status <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;Error&quot;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #800080;">$colour</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Red&quot;</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> <span style="color: #800080;">$colour</span> <span style="color: #800080;">$s</span>.Report <span style="color: #800080;">$s</span>.Status <span style="color: #800080;">$s</span>.LastExecuted <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-Table</span> <span style="color: #008080; font-style: italic;">-AutoSize</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>After running this script successfully you should be something like below;</p>
<p><a href="http://www.youdidwhatwithtsql.com/monitoring-ssrs-subscriptions-powershell/1392/powershell_ssrs-2" rel="attachment wp-att-1399"><img class="alignnone size-full wp-image-1399" title="powershell ssrs" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/11/powershell_ssrs1.png" alt="powershell ssrs1 Monitoring SSRS Subscriptions with Powershell" width="677" height="342" /></a></p>
<p>&nbsp;</p>
<p><map name='google_ad_map_1392_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1392?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1392_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1392&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fmonitoring-ssrs-subscriptions-powershell%2F1392' title="Monitoring SSRS Subscriptions with Powershell" alt=" Monitoring SSRS Subscriptions with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/monitoring-ssrs-subscriptions-powershell/1392">Monitoring SSRS Subscriptions with Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/monitoring-ssrs-subscriptions-powershell/1392" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/monitoring-ssrs-subscriptions-powershell/1392/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Powershell to increment the computers date</title>
		<link>http://www.youdidwhatwithtsql.com/powershell-increment-computers-date/1389</link>
		<comments>http://www.youdidwhatwithtsql.com/powershell-increment-computers-date/1389#comments</comments>
		<pubDate>Thu, 10 Nov 2011 16:10:14 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1389</guid>
		<description><![CDATA[Here&#8217;s a little snippet of Powershell code I used recently to test some TSQL that runs according to a two week schedule. This code will increment the date by one day, up to the maximum specified in $days, sleeping in between for a short while. The date is set back correctly at the end. Far [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/powershell-increment-computers-date/1389">Using Powershell to increment the computers date</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little snippet of <a title="Windows Powershell" href="http://en.wikipedia.org/wiki/Windows_PowerShell" target="_blank">Powershell</a> code I used recently to test some <a title="TSQL" href="http://en.wikipedia.org/wiki/Transact-SQL" target="_blank">TSQL</a> that runs according to a two week schedule.</p>
<p>This code will increment the date by one day, up to the maximum specified in <strong>$days</strong>, sleeping in between for a short while. The date is set back correctly at the end. Far from rocket science but it helps me test various bits of code in minutes instead of 2 weeks!</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1389code22'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p138922"><td class="code" id="p1389code22"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Number of days to increment the date by</span>
<span style="color: #800080;">$days</span> <span style="color: pink;">=</span> <span style="color: #804000;">14</span>;
&nbsp;
<span style="color: #0000FF;">for</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$counter</span><span style="color: pink;">=</span><span style="color: #804000;">0</span>; <span style="color: #800080;">$counter</span> <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$days</span>; <span style="color: #800080;">$counter</span><span style="color: pink;">++</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-weight: bold;">Set-Date</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span>.AddDays<span style="color: #000000;">&#40;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #008000;"># Sleep for 2 minutes so the code gets a chance to run</span>
	<span style="color: #008080; font-weight: bold;">Start-Sleep</span> <span style="color: #008080; font-style: italic;">-Seconds</span> <span style="color: #804000;">120</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># Set the date back correctly</span>
<span style="color: #008080; font-weight: bold;">Set-Date</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span>.AddDays<span style="color: #000000;">&#40;</span><span style="color: pink;">-</span><span style="color: #800080;">$days</span><span style="color: #000000;">&#41;</span>;</pre></td></tr></table></div>

<p><map name='google_ad_map_1389_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1389?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1389_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1389&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fpowershell-increment-computers-date%2F1389' title="Using Powershell to increment the computers date" alt=" Using Powershell to increment the computers date" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/powershell-increment-computers-date/1389">Using Powershell to increment the computers date</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/powershell-increment-computers-date/1389" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/powershell-increment-computers-date/1389/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing a Failover Cluster with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/testing-failover-cluster-powershell/1377</link>
		<comments>http://www.youdidwhatwithtsql.com/testing-failover-cluster-powershell/1377#comments</comments>
		<pubDate>Thu, 03 Nov 2011 11:26:22 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[failover cluster]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1377</guid>
		<description><![CDATA[Just a quick Powershell snippet that I&#8217;m going to use to run validation tests on one of my staging Failover Clusters during OOH. The script below will take some services offline, run the validation tests, before bringing the appropriate cluster groups back online. The report will be saved using the date as the name. To [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/testing-failover-cluster-powershell/1377">Testing a Failover Cluster with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Just a quick <a title="Windows Powershell" href="http://en.wikipedia.org/wiki/Windows_PowerShell" target="_blank">Powershell</a> snippet that I&#8217;m going to use to run validation tests on one of my staging Failover Clusters during OOH.</p>
<p>The script below will take some services offline, run the validation tests, before bringing the appropriate cluster groups back online. The report will be saved using the date as the name. To use this you will need to set <strong>$cluster</strong> appropriately and perhaps customize the cluster groups that are brought offline &amp; online.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1377code24'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p137724"><td class="code" id="p1377code24"><pre class="powershell" style="font-family:monospace;">Import<span style="color: pink;">-</span>Module FailoverClusters;
&nbsp;
<span style="color: #008000;"># Set cluster name</span>
<span style="color: #800080;">$cluster</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Cluster&quot;</span>;
&nbsp;
<span style="color: #008000;"># Date stamp used for report name</span>
<span style="color: #800080;">$date</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Date</span> <span style="color: #008080; font-style: italic;">-Format</span> <span style="color: #800000;">&quot;yyyyMMdd&quot;</span>;
&nbsp;
<span style="color: #008000;"># Take cluster services offline. You may need to customise this</span>
<span style="color: #008000;"># according to your specific needs</span>
Stop<span style="color: pink;">-</span>ClusterGroup <span style="color: pink;">-</span>Cluster <span style="color: #800080;">$cluster</span> <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800000;">&quot;ClusterDtc&quot;</span>;
Stop<span style="color: pink;">-</span>ClusterGroup <span style="color: pink;">-</span>Cluster <span style="color: #800080;">$cluster</span> <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800000;">&quot;SQL Server (MSSQLSERVER)&quot;</span>;
&nbsp;
<span style="color: #008000;"># Test Cluster</span>
Test<span style="color: pink;">-</span>Cluster <span style="color: pink;">-</span>Cluster <span style="color: #800080;">$cluster</span> <span style="color: pink;">-</span>ReportName <span style="color: #800000;">&quot;$date&quot;</span>;
&nbsp;
<span style="color: #008000;"># Bring services back online</span>
Start<span style="color: pink;">-</span>ClusterGroup <span style="color: pink;">-</span>Cluster <span style="color: #800080;">$cluster</span> <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800000;">&quot;ClusterDtc&quot;</span>;
Start<span style="color: pink;">-</span>ClusterGroup <span style="color: pink;">-</span>Cluster <span style="color: #800080;">$cluster</span> <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800000;">&quot;SQL Server (MSSQLSERVER)&quot;</span>;</pre></td></tr></table></div>

<p>The output will look something like below&#8230;</p>
<pre>Name                       OwnerNode                                      State
----                       ---------                                      -----
ClusterDtc            	   Node1                                 	  Offline
SQL Server (MSSQLSERVER)   Node1                                 	  Offline
WARNING: Cluster Configuration - Validate Resource Status: The test reported
some warnings..
WARNING: Network - Validate IP Configuration: The test reported some warnings..
WARNING:
Test Result:
ClusterConditionallyApproved
Testing has completed successfully. The configuration appears to be suitable
for clustering.  However, you should review the report because it may contain
warnings which you should address to attain the highest availability.
Test report file path: C:\Users\ClusterAdmin\AppData\Local\Temp\20111103.mht
20111103.mht
ClusterDtc            	   Node1                                 	 Online
SQL Server (MSSQLSERVER)   Node1                                 	 Online</pre>
<p><map name='google_ad_map_1377_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1377?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1377_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1377&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Ftesting-failover-cluster-powershell%2F1377' title="Testing a Failover Cluster with Powershell" alt=" Testing a Failover Cluster with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/testing-failover-cluster-powershell/1377">Testing a Failover Cluster with Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/testing-failover-cluster-powershell/1377" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/testing-failover-cluster-powershell/1377/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Domain user password expiry with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/domain-user-password-expiry-powershell/1372</link>
		<comments>http://www.youdidwhatwithtsql.com/domain-user-password-expiry-powershell/1372#comments</comments>
		<pubDate>Thu, 13 Oct 2011 11:14:17 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Password expiry]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/?p=1372</guid>
		<description><![CDATA[I needed to figure out a method for producing alerts when a domain account is approaching the password reset date. Here it is in a few lines of Powershell&#8230; ?View Code POWERSHELL# Set name here $name = &#34;Rhys Campbell&#34;; $user = Get-ADUser -LDAPFilter &#34;(Name=$name)&#34; -Properties PasswordLastSet; $days = $&#40;Get-ADDefaultDomainPasswordPolicy&#41;.MaxPasswordAge; $expires = $user.PasswordLastSet + $days; $days_left [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/domain-user-password-expiry-powershell/1372">Domain user password expiry with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I needed to figure out a method for producing alerts when a domain account is approaching the password reset date. Here it is in a few lines of Powershell&#8230;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1372code26'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p137226"><td class="code" id="p1372code26"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Set name here</span>
<span style="color: #800080;">$name</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Rhys Campbell&quot;</span>;
<span style="color: #800080;">$user</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>ADUser <span style="color: pink;">-</span>LDAPFilter <span style="color: #800000;">&quot;(Name=$name)&quot;</span> <span style="color: pink;">-</span>Properties PasswordLastSet;
<span style="color: #800080;">$days</span> <span style="color: pink;">=</span> $<span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>ADDefaultDomainPasswordPolicy<span style="color: #000000;">&#41;</span>.MaxPasswordAge;
<span style="color: #800080;">$expires</span> <span style="color: pink;">=</span> <span style="color: #800080;">$user</span>.PasswordLastSet <span style="color: pink;">+</span> <span style="color: #800080;">$days</span>;
<span style="color: #800080;">$days_left</span> <span style="color: pink;">=</span> <span style="color: #800080;">$expires</span> <span style="color: pink;">-</span> $<span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span>;
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Password for $name expires on $expires which is in $($days_left.Days) days.&quot;</span>;</pre></td></tr></table></div>

<p>This will display something along the lines of;</p>
<pre>Password for Rhys Campbell expires on 11/18/2011 08:19:36 which is in 35 days.</pre>
<p><map name='google_ad_map_1372_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1372?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1372_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1372&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fdomain-user-password-expiry-powershell%2F1372' title="Domain user password expiry with Powershell" alt=" Domain user password expiry with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/domain-user-password-expiry-powershell/1372">Domain user password expiry with Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/domain-user-password-expiry-powershell/1372" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/domain-user-password-expiry-powershell/1372/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking Disk alignment with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/checking-disk-alignment-with-powershell/1362</link>
		<comments>http://www.youdidwhatwithtsql.com/checking-disk-alignment-with-powershell/1362#comments</comments>
		<pubDate>Wed, 05 Oct 2011 19:36:04 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[disk alignment]]></category>
		<category><![CDATA[DISKPART]]></category>
		<category><![CDATA[StartingOffset]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/checking-disk-alignment-with-powershell/1362</guid>
		<description><![CDATA[Disk alignment has been well discussed on the web and the methods to check this always seem to use wmic or DISKPART. I&#8217;ve always loathed wmi so here&#8217;s a few lines of Powershell that achieves the same thing; ?View Code POWERSHELL$sqlserver = &#34;sqlinstance&#34;; # Get disk partitions $partitions = Get-WmiObject -ComputerName $sqlserver -Class Win32_DiskPartition; $partitions [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/checking-disk-alignment-with-powershell/1362">Checking Disk alignment with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://itknowledgeexchange.techtarget.com/sql-server/how-much-performance-are-you-loosing-by-not-aligning-your-drives/">Disk alignment</a> has been well discussed on the web and the methods to check this always seem to use <a title="wmic and DISKPART for disgn alignment" href="http://sqlskills.com/BLOGS/PAUL/post/Using-diskpart-to-check-disk-partition-alignment.aspx">wmic or DISKPART</a>. I&#8217;ve always loathed wmi so here&#8217;s a few lines of Powershell that achieves the same thing;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1362code28'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p136228"><td class="code" id="p1362code28"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$sqlserver</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;sqlinstance&quot;</span>;
<span style="color: #008000;"># Get disk partitions</span>
<span style="color: #800080;">$partitions</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-WmiObject</span> <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$sqlserver</span> <span style="color: #008080; font-style: italic;">-Class</span> Win32_DiskPartition;
<span style="color: #800080;">$partitions</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> <span style="color: #008080; font-style: italic;">-Property</span> DeviceId<span style="color: pink;">,</span> Name<span style="color: pink;">,</span> Description<span style="color: pink;">,</span> BootPartition<span style="color: pink;">,</span> PrimaryPartition<span style="color: pink;">,</span> Index<span style="color: pink;">,</span> Size<span style="color: pink;">,</span> BlockSize<span style="color: pink;">,</span> StartingOffset <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-Table</span> <span style="color: #008080; font-style: italic;">-AutoSize</span>;</pre></td></tr></table></div>

<p>This will display something looking like below;</p>
<pre>DeviceId              Name                  Description             BootPartition PrimaryPartition Index          Size BlockSize StartingOffset
--------              ----                  -----------             ------------- ---------------- -----          ---- --------- --------------
Disk #2, Partition #0 Disk #2, Partition #0 Installable File System         False             True     0 1099523162112       512        1048576
Disk #3, Partition #0 Disk #3, Partition #0 Installable File System         False             True     0  536878252032       512        1048576
Disk #4, Partition #0 Disk #4, Partition #0 Installable File System         False             True     0    1082130432       512          65536
Disk #5, Partition #0 Disk #5, Partition #0 Installable File System         False             True     0    1082130432       512          65536
Disk #1, Partition #0 Disk #1, Partition #0 Installable File System         False             True     0  107376279552       512        1048576
Disk #0, Partition #0 Disk #0, Partition #0 Installable File System          True             True     0     104857600       512        1048576
Disk #0, Partition #1 Disk #0, Partition #1 Installable File System         False             True     1   81684070400       512      105906176
Disk #0, Partition #2 Disk #0, Partition #2 Installable File System         False             True     2  104857600000       512    81789976576
Disk #0, Partition #3 Disk #0, Partition #3 Installable File System         False             True     3  104857600000       512   186647576576</pre>
<p>A <a href="http://msdn.microsoft.com/en-us/library/dd758814(v=sql.100).aspx">64K cluster size</a> is good for SQL Server. But what about the offset? The simple calculation below can be used to check this&#8230;</p>
<p><strong>StartingOffset / BlockSize / 128 </strong>(a 64K cluster has 128 sectors assuming a 512 block size).</p>
<p>If this calculation spits out a number with any decimal places then you have some disk aligning to do.</p>
<p><strong><font color="#666666"></font></strong></p>
<p><map name='google_ad_map_1362_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1362?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1362_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1362&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fchecking-disk-alignment-with-powershell%2F1362' title="Checking Disk alignment with Powershell" alt=" Checking Disk alignment with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/checking-disk-alignment-with-powershell/1362">Checking Disk alignment with Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/checking-disk-alignment-with-powershell/1362" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/checking-disk-alignment-with-powershell/1362/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Audit VLFs on your SQL Server</title>
		<link>http://www.youdidwhatwithtsql.com/audit-vlfs-on-your-sql-server/1358</link>
		<comments>http://www.youdidwhatwithtsql.com/audit-vlfs-on-your-sql-server/1358#comments</comments>
		<pubDate>Tue, 04 Oct 2011 20:47:55 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Virtual Log Files]]></category>
		<category><![CDATA[VLF]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/audit-vlfs-on-your-sql-server/1358</guid>
		<description><![CDATA[I&#8217;ve been reading a bit about VLFs (Virtual Log Files) this week. I&#8217;ve found quite a few interesting links, especially this one, informing us that there&#8217;s such a thing as too few or too many VLFs. We can view details about VLFs using the DBCC LOGINFO TSQL command. This only works against the current database [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/audit-vlfs-on-your-sql-server/1358">Audit VLFs on your SQL Server</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been <a href="http://sqlblog.com/blogs/linchi_shea/archive/2009/02/09/performance-impact-a-large-number-of-virtual-log-files-part-i.aspx">reading a bit about VLFs</a> (Virtual Log Files) this week. I&#8217;ve found quite a few interesting links, especially this one, informing us that there&#8217;s such a thing as <a href="http://sqlskills.com/BLOGS/KIMBERLY/post/Transaction-Log-VLFs-too-many-or-too-few.aspx">too few or too many VLFs.</a> </p>
<p>We can view details about VLFs using the DBCC LOGINFO TSQL command. This only works against the current database context but I decided to make this process less tedious, and human-readable, so I knocked up a quick script;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1358code31'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p135831"><td class="code" id="p1358code31"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">-- Create a temp table to hold log info</span>
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> #tmp_log_info
<span style="color: #808080;">&#40;</span>
      FileId <span style="color: #0000FF;">INTEGER</span>,
      FileSize <span style="color: #0000FF;">BIGINT</span>,
      StartOffSet <span style="color: #0000FF;">BIGINT</span>,
      <span style="color: #808080;">&#91;</span>Status<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INTEGER</span>,
      FSeqNo <span style="color: #0000FF;">INTEGER</span>,
      Parity <span style="color: #0000FF;">SMALLINT</span>,
      CreateLSN <span style="color: #0000FF;">NUMERIC</span><span style="color: #808080;">&#40;</span><span style="color: #000;">38</span>,<span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">&#41;</span>;
&nbsp;
<span style="color: #008080;">-- Same as above but with database name</span>
<span style="color: #008080;">-- Can insert in one statement</span>
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> #log_info
<span style="color: #808080;">&#40;</span>
      FileId <span style="color: #0000FF;">INTEGER</span>,
      FileSize <span style="color: #0000FF;">BIGINT</span>,
      StartOffSet <span style="color: #0000FF;">BIGINT</span>,
      <span style="color: #808080;">&#91;</span>Status<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INTEGER</span>,
      FSeqNo <span style="color: #0000FF;">INTEGER</span>,
      Parity <span style="color: #0000FF;">SMALLINT</span>,
      CreateLSN <span style="color: #0000FF;">NUMERIC</span><span style="color: #808080;">&#40;</span><span style="color: #000;">38</span>,<span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>,
      <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">Database</span><span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">128</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">&#41;</span>;
&nbsp;
<span style="color: #0000FF;">EXEC</span> sp_MsForEachDb <span style="color: #FF0000;">'INSERT INTO #tmp_log_info EXEC('</span><span style="color: #FF0000;">'DBCC LOGINFO(?)'</span><span style="color: #FF0000;">');
                              INSERT INTO #log_info
                               SELECT *, '</span><span style="color: #FF0000;">'?'</span><span style="color: #FF0000;">'
                              FROM #tmp_log_info;
                              TRUNCATE TABLE #tmp_log_info;'</span>;
&nbsp;
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">Database</span><span style="color: #808080;">&#93;</span>,
            <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> Vlf_count,
            <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#40;</span>FileSize<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">FLOAT</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">1048576</span>  <span style="color: #0000FF;">AS</span> biggest_vlf_MB,
            <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MIN</span><span style="color: #808080;">&#40;</span>FileSize<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">FLOAT</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">1048576</span> <span style="color: #0000FF;">AS</span> smallest_vlf_MB
<span style="color: #0000FF;">FROM</span> #log_info
<span style="color: #0000FF;">GROUP</span> <span style="color: #0000FF;">BY</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">Database</span><span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span> <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">DESC</span>;
&nbsp;
&nbsp;
<span style="color: #008080;">-- Clean up</span>
<span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">TABLE</span> #tmp_log_info;
<span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">TABLE</span> #log_info;</pre></td></tr></table></div>

<p>This will display a summary report for all databases on the instance of SQL Server.</p>
<p><strong>Database &#8211; </strong>The database the log file belongs to.</p>
<p><strong>Vlf_count &#8211; </strong>The total number of VLFs.</p>
<p><strong>biggest_vlf_MB &#8211; </strong>The biggest virtual log file in MB.</p>
<p><strong>smallest_vlf_MB &#8211; </strong>The smallest virtual log file in MB.</p>
<pre>Database	Vlf_count	biggest_vlf_MB	smallest_vlf_MB
msdb		26		0.4453125	0.2421875
master		5		0.25		0.2421875
model		3		0.25		0.2421875
tempdb		2		0.25		0.2421875
ft_test		2		0.3125		0.2421875</pre>
<p><strong>UPDATE: </strong>Just found a <a href="http://sqlserverpedia.com/blog/sql-server-bloggers/find-the-number-of-vlfs-for-all-databases/">very similar post here</a>.</p>
<p><strong>UPDATE: </strong>Thought I&#8217;d try to bring something to the table and come up with a pure-powershell way to do this but it doesn&#8217;t seem that the VLF information is exposed;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1358code32'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p135832"><td class="code" id="p1358code32"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$server</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;localhost&quot;</span>;
<span style="color: #008000;"># Load SMO </span>
<span style="color: #000000;">&#91;</span><span style="color: #008080;">System.Reflection.Assembly</span><span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.SqlServer.Smo&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span>; 
<span style="color: #008000;"># create server objects </span>
<span style="color: #800080;">$srv</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> Microsoft.SqlServer.Management.SMO.Server <span style="color: #800080;">$server</span>;
<span style="color: #800080;">$db</span> <span style="color: pink;">=</span> <span style="color: #800080;">$srv</span>.Databases<span style="color: #000000;">&#91;</span><span style="color: #800000;">&quot;tempdb&quot;</span><span style="color: #000000;">&#93;</span>;
&nbsp;
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$log</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$db</span>.LogFiles<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800080;">$log</span>.Name;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;=================&quot;</span>;
	<span style="color: #008000;"># Output each property</span>
	<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$p</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$log</span>.Properties<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800080;">$p</span>.Name;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Exposed logfile properties&#8230;</p>
<pre>
templog
=================
FileName
Growth
GrowthType
ID
MaxSize
Size
UsedSpace
BytesReadFromDisk
BytesWrittenToDisk
IsOffline
IsReadOnly
IsReadOnlyMedia
IsSparse
NumberOfDiskReads
NumberOfDiskWrites
PolicyHealthState
VolumeFreeSpace
</pre>
<p>If anyone knows a way I&#8217;d be interested to hear. Cheers</p>
<p><map name='google_ad_map_1358_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1358?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1358_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1358&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Faudit-vlfs-on-your-sql-server%2F1358' title="Audit VLFs on your SQL Server" alt=" Audit VLFs on your SQL Server" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/audit-vlfs-on-your-sql-server/1358">Audit VLFs on your SQL Server</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/audit-vlfs-on-your-sql-server/1358" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/audit-vlfs-on-your-sql-server/1358/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

