<?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; Excel Automation</title>
	<atom:link href="http://www.youdidwhatwithtsql.com/tag/excel-automation/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>SQL Server Audit with Powershell Excel Automation</title>
		<link>http://www.youdidwhatwithtsql.com/sql-server-audit-with-powershell-excel-automation/703</link>
		<comments>http://www.youdidwhatwithtsql.com/sql-server-audit-with-powershell-excel-automation/703#comments</comments>
		<pubDate>Sat, 27 Mar 2010 18:57:50 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Excel Automation]]></category>
		<category><![CDATA[SQL Server Database Audit]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/sql-server-audit-with-powershell-excel-automation/703</guid>
		<description><![CDATA[Here&#8217;s neat little Powershell script you can use to audit your SQL Server databases. The script is dependant on the SQL Browser service, to discover instances, so you will need to make sure this is running. This will allow you to audit all SQL Server instances on the localhost with details of your databases and [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/sql-server-audit-with-powershell-excel-automation/703">SQL Server Audit with Powershell Excel Automation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s neat little <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target="_blank">Powershell</a> script you can use to audit your <a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" target="_blank">SQL Server</a> databases. The script is dependant on the <a href="http://msdn.microsoft.com/en-us/library/ms181087.aspx" target="_blank">SQL Browser</a> service, to discover instances, so you will need to make sure this is running. This will allow you to audit all SQL Server instances on the localhost with details of your databases and associated information. I use <a href="http://msdn.microsoft.com/en-us/library/ms162169.aspx" target="_blank">SMO</a> here so it should be pretty easy to customise for your own purposes. Just run the script and a nicely formatted Excel report of your databases will be produced. Enjoy!</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('p703code2'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7032"><td class="code" id="p703code2"><pre class="powershell" style="font-family:monospace;"><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: #800080;">$smoObj</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>Microsoft.SqlServer.Management.Smo.SmoApplication<span style="color: #000000;">&#93;</span>;
&nbsp;
<span style="color: #008000;"># This gets the sql server</span>
<span style="color: #800080;">$sql</span> <span style="color: pink;">=</span> <span style="color: #800080;">$smoObj</span>::EnumAvailableSqlServers<span style="color: #000000;">&#40;</span><span style="color: #800080;">$false</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #008000;"># Automate Excel</span>
<span style="color: #800080;">$xl</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #008080; font-style: italic;">-ComObject</span> Excel.Application;
<span style="color: #800080;">$xl</span>.Visible <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>;
<span style="color: #800080;">$xl</span> <span style="color: pink;">=</span> <span style="color: #800080;">$xl</span>.Workbooks.Add<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #800080;">$Sheet</span> <span style="color: pink;">=</span> <span style="color: #800080;">$xl</span>.Worksheets.Item<span style="color: #000000;">&#40;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #800080;">$row</span> <span style="color: pink;">=</span> <span style="color: #804000;">1</span>;
&nbsp;
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$sqlserver</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$sql</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	 <span style="color: #008000;"># headers</span>
     <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Sql Server:&quot;</span>;
     <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$sqlserver</span>.Name;
     <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>.Font.Bold <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>;
     <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span>.Font.Bold <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>;
	<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">3</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>;
     	<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">4</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Instance:&quot;</span>;
     	<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">5</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$sqlserver</span>.Instance;
     	<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">4</span><span style="color: #000000;">&#41;</span>.Font.Bold <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>;
     	<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">5</span><span style="color: #000000;">&#41;</span>.Font.Bold <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>;
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">6</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>;
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">7</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Version: &quot;</span>;
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">8</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$sqlserver</span>.Version;
     	<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">7</span><span style="color: #000000;">&#41;</span>.Font.Bold <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>;
     	<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">8</span><span style="color: #000000;">&#41;</span>.Font.Bold <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>;
&nbsp;
	 <span style="color: #008000;"># Prettify headers</span>
	 <span style="color: #0000FF;">for</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$i</span> <span style="color: pink;">=</span> <span style="color: #804000;">1</span>; <span style="color: #800080;">$i</span> <span style="color: #FF0000;">-le</span> <span style="color: #804000;">8</span>; <span style="color: #800080;">$i</span><span style="color: pink;">++</span><span style="color: #000000;">&#41;</span>
	 <span style="color: #000000;">&#123;</span>
	 	<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span><span style="color: #800080;">$i</span><span style="color: #000000;">&#41;</span>.Interior.ColorIndex <span style="color: pink;">=</span> <span style="color: #804000;">50</span>;
     		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span><span style="color: #800080;">$i</span><span style="color: #000000;">&#41;</span>.Font.ColorIndex <span style="color: pink;">=</span> <span style="color: #804000;">20</span>;
	 <span style="color: #000000;">&#125;</span>
&nbsp;
	 <span style="color: #008000;"># Create obj for this sql server</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;">$sqlserver</span>.Name;
	 <span style="color: #008000;"># Get the databases on this sql server</span>
	 <span style="color: #800080;">$databases</span> <span style="color: pink;">=</span> <span style="color: #800080;">$srv</span>.Databases;
&nbsp;
	 <span style="color: #008000;"># Increase rowcount for formatting</span>
	 <span style="color: #800080;">$row</span> <span style="color: pink;">+=</span> <span style="color: #804000;">2</span>;
&nbsp;
	 <span style="color: #008000;"># Add column headers for databases</span>
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Database&quot;</span>;
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Size&quot;</span>;
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">3</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;SpaceAvailable&quot;</span>;
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">4</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;State&quot;</span>;
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">5</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Table Count&quot;</span>;
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">6</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Collation&quot;</span>;
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">7</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Compatibility Level&quot;</span>;
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">8</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Create Date&quot;</span>;
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">9</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Index Space Usage&quot;</span>;
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">10</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Owner&quot;</span>;
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">11</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Last Backup&quot;</span>;
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">12</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Trigger Count&quot;</span>;
	 <span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">13</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;UDF Count&quot;</span>;
	 <span style="color: #0000FF;">for</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$i</span> <span style="color: pink;">=</span> <span style="color: #804000;">1</span>; <span style="color: #800080;">$i</span> <span style="color: #FF0000;">-le</span> <span style="color: #804000;">13</span>; <span style="color: #800080;">$i</span><span style="color: pink;">++</span><span style="color: #000000;">&#41;</span>
	 <span style="color: #000000;">&#123;</span>
	 	<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span><span style="color: #800080;">$i</span><span style="color: #000000;">&#41;</span>.Interior.ColorIndex <span style="color: pink;">=</span> <span style="color: #804000;">35</span>;
     		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span><span style="color: #800080;">$i</span><span style="color: #000000;">&#41;</span>.Font.ColorIndex <span style="color: pink;">=</span> <span style="color: #804000;">0</span>;
		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #800080;">$i</span><span style="color: #000000;">&#41;</span>.Font.Bold <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>;
	 <span style="color: #000000;">&#125;</span>
	 <span style="color: #800080;">$row</span><span style="color: pink;">++</span>;
	 <span style="color: #008000;"># Work through each database in the collection</span>
	 <span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$db</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$databases</span><span style="color: #000000;">&#41;</span>
	 <span style="color: #000000;">&#123;</span>
	 	<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$db</span>.Name;
		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$db</span>.Size;
		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">3</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$db</span>.SpaceAvailable;
		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">4</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$db</span>.State;
		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">5</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$db</span>.Tables.Count;
		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">6</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$db</span>.Collation;
		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">7</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$db</span>.CompatibilityLevel;
		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">8</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$db</span>.CreateDate;
		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">9</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$db</span>.IndexSpaceUsage;
		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">10</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$db</span>.Owner;
		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">11</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$db</span>.LastBackupDate;
		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">12</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$db</span>.Triggers.Count;
		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span> <span style="color: #804000;">13</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">=</span> <span style="color: #800080;">$db</span>.UserDefinedFunctions.Count;
		<span style="color: #0000FF;">for</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$i</span> <span style="color: pink;">=</span> <span style="color: #804000;">1</span>; <span style="color: #800080;">$i</span> <span style="color: #FF0000;">-le</span> <span style="color: #804000;">13</span>; <span style="color: #800080;">$i</span><span style="color: pink;">++</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
	 		<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span><span style="color: #800080;">$i</span><span style="color: #000000;">&#41;</span>.Interior.ColorIndex <span style="color: pink;">=</span> <span style="color: #804000;">0</span>;
     			<span style="color: #800080;">$Sheet</span>.Cells.Item<span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span><span style="color: pink;">,</span><span style="color: #800080;">$i</span><span style="color: #000000;">&#41;</span>.Font.ColorIndex <span style="color: pink;">=</span> <span style="color: #804000;">0</span>;			
		<span style="color: #000000;">&#125;</span>
		<span style="color: #800080;">$row</span><span style="color: pink;">++</span>;
	 <span style="color: #000000;">&#125;</span>
&nbsp;
	 <span style="color: #800080;">$row</span><span style="color: pink;">++</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># Apply autoformat</span>
<span style="color: #800080;">$Sheet</span>.UsedRange.EntireColumn.AutoFit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/03/powershell_excel_sql_server_database_audit.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="powershell excel sql server database audit" border="0" alt="powershell excel sql server database audit thumb SQL Server Audit with Powershell Excel Automation" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/03/powershell_excel_sql_server_database_audit_thumb.png" width="644" height="393" /></a></p>
<p><map name='google_ad_map_703_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/703?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_703_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=703&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fsql-server-audit-with-powershell-excel-automation%2F703' title="SQL Server Audit with Powershell Excel Automation" alt=" SQL Server Audit with Powershell Excel Automation" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/sql-server-audit-with-powershell-excel-automation/703">SQL Server Audit with Powershell Excel Automation</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/sql-server-audit-with-powershell-excel-automation/703" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/sql-server-audit-with-powershell-excel-automation/703/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

