<?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>MattLog.net &#187; PowerShell</title>
	<atom:link href="http://mattlog.net/tag/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://mattlog.net</link>
	<description>Matts Admin Tips</description>
	<lastBuildDate>Wed, 21 Jul 2010 01:37:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Output Exchange 2007 Retry/Ready Messages</title>
		<link>http://mattlog.net/2009/04/17/output-exchange-2007-retryready-messages/</link>
		<comments>http://mattlog.net/2009/04/17/output-exchange-2007-retryready-messages/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 05:04:29 +0000</pubDate>
		<dc:creator>Matt Shadbolt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[EMS]]></category>
		<category><![CDATA[Exchange 2007]]></category>
		<category><![CDATA[Get-Message]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://mattlog.net/?p=150</guid>
		<description><![CDATA[Here&#8217;s a quick and dirty Exchange 2007 command-let that will output all the outgoing emails that are not being delivered. It Checks the message status (NOT &#8220;Active) and the message retry count (GT 0) and outputs the results. Get-Message -Server SERVER01 -IncludeRecipientInfo &#124; Where{$_.RetryCount -gt 0} &#124; Where{$_.Status -ne &#8220;Active&#8221;} &#124; SELECT FromAddress, Recipients, LastError [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick and dirty Exchange 2007 command-let that will output all the outgoing emails that are not being delivered. It Checks the message status (NOT &#8220;Active) and the message retry count (GT 0) and outputs the results.</p>
<p>Get-Message -Server SERVER01 -IncludeRecipientInfo | Where{$_.RetryCount -gt 0} | Where{$_.Status -ne &#8220;Active&#8221;} | SELECT FromAddress, Recipients, LastError | Format-Table</p>
]]></content:encoded>
			<wfw:commentRss>http://mattlog.net/2009/04/17/output-exchange-2007-retryready-messages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auto Email when StorageGroupCopy Status Failed</title>
		<link>http://mattlog.net/2009/03/12/auto-email-when-storagegroupcopy-status-failed/</link>
		<comments>http://mattlog.net/2009/03/12/auto-email-when-storagegroupcopy-status-failed/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 05:22:14 +0000</pubDate>
		<dc:creator>Matt Shadbolt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Exchange 2007]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SCR]]></category>
		<category><![CDATA[StorageGroupCopyStatus]]></category>

		<guid isPermaLink="false">http://mattlog.net/?p=129</guid>
		<description><![CDATA[Man! I&#8217;m killing these powershell scripts today &#8211; and they&#8217;ve all been related to alerting/reporting via email. If you&#8217;ve missed my two other posts &#8211; there is a mailbox size report (http://mattlog.net/2009/03/12/auto-email-exchange-2007-mailbox-report/) and a StorageGroupCopyStatus report (http://mattlog.net/2009/03/12/auto-email-exchange-2007-storagegroupcopystatus/) This one is a little more useful. Basically, this PowerShell script checks the SummaryCopyStatus and checks that it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Man! I&#8217;m killing these powershell scripts today &#8211; and they&#8217;ve all been related to alerting/reporting via email. If you&#8217;ve missed my two other posts &#8211; there is a mailbox size report (<a href="http://mattlog.net/2009/03/12/auto-email-exchange-2007-mailbox-report/">http://mattlog.net/2009/03/12/auto-email-exchange-2007-mailbox-report/</a>) and a StorageGroupCopyStatus report (<a href="http://mattlog.net/2009/03/12/auto-email-exchange-2007-storagegroupcopystatus/">http://mattlog.net/2009/03/12/auto-email-exchange-2007-storagegroupcopystatus/</a>)</p>
<p>This one is a little more useful.</p>
<p>Basically, this PowerShell script checks the SummaryCopyStatus and checks that it&#8217;s &#8220;Healthy&#8221; &#8211; if not, it will send an email reporting which Storage Group copy has failed.  You can run this script every hour or so, and be alerted when any SCR status has gone bad.</p>
<p>This is based on the same email code as my previous two posts. Bare in mind that I&#8217;m NOT a developer and my code is more than likely inefficient and ugly!</p>
<p>You can download the script <a href="http://mattlog.net/wp-content/uploads/2009/03/checkscrstatus.ps1">CheckSCRStatus.ps1</a></p>
<p>Or view the code:</p>
<p>$SCRStatus = Get-StorageGroupCopyStatus -Server PRIMARYSERVER -StandbyMachine SECONDARYSERVER | Where {$_.StorageGroupName -eq &#8220;First Storage Group&#8221;}<br />
if ($SCRStatus.SummaryCopyStatus -ne &#8220;Healthy&#8221;)<br />
{<br />
$MessageBody = &#8220;The SCR for &#8221; + $SCRStatus.StorageGroupName + &#8221; has failed&#8221;<br />
$FromAddress = &#8220;FromAddress@yourdomain.com&#8221;<br />
$ToAddress = &#8220;ToAddress@yourdomain.com&#8221;<br />
$MessageSubject = &#8220;SCR Status Failure&#8221;<br />
$SendingServer = &#8220;MAILSERVER&#8221;<br />
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody<br />
$SMTPMessage.IsBodyHtml = $true<br />
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer<br />
$SMTPClient.Send($SMTPMessage)<br />
}<br />
Else<br />
{<br />
Write-Host &#8220;First Storage Group All Good!&#8221;<br />
}<br />
$SCRStatus2 = Get-StorageGroupCopyStatus -Server PRIMARYSERVER -StandbyMachine SECONDARYSERVER | Where {$_.StorageGroupName -eq &#8220;Second Storage Group&#8221;}<br />
if ($SCRStatus2.SummaryCopyStatus -ne &#8220;Healthy&#8221;)<br />
{<br />
$MessageBody = &#8220;The SCR for &#8221; + $SCRStatus2.StorageGroupName + &#8221; has failed&#8221;<br />
$FromAddress = &#8220;FromAddress@yourdomain.com&#8221;<br />
$ToAddress = &#8220;ToAddress@yourdomain.com&#8221;<br />
$MessageSubject = &#8220;SCR Status Failure&#8221;<br />
$SendingServer = &#8220;MAILSERVER&#8221;<br />
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody<br />
$SMTPMessage.IsBodyHtml = $true<br />
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer<br />
$SMTPClient.Send($SMTPMessage)<br />
}<br />
Else<br />
{<br />
Write-Host &#8220;Second Storage Group All Good!&#8221;<br />
Exit<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://mattlog.net/2009/03/12/auto-email-when-storagegroupcopy-status-failed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auto Email Exchange 2007 StorageGroupCopyStatus</title>
		<link>http://mattlog.net/2009/03/12/auto-email-exchange-2007-storagegroupcopystatus/</link>
		<comments>http://mattlog.net/2009/03/12/auto-email-exchange-2007-storagegroupcopystatus/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 04:02:15 +0000</pubDate>
		<dc:creator>Matt Shadbolt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Exchange 2007]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SCR]]></category>
		<category><![CDATA[Standby Continuous Replication]]></category>
		<category><![CDATA[StorageGroupCopyStatus]]></category>

		<guid isPermaLink="false">http://mattlog.net/?p=124</guid>
		<description><![CDATA[Exchange 2007&#8242;s Storage Group Copy feature is one of my favourites, however the one area it is really lacking is the reporting. You need to manually run the Get-StorageGroupCopyStatus -Server INITIALSERVER -StandbyMachine TARGETSERVER to find that your SCR is Healthy. I&#8217;ve been playing around writing some simple PowerShell scripts today so I thought I would [...]]]></description>
			<content:encoded><![CDATA[<p>Exchange 2007&#8242;s Storage Group Copy feature is one of my favourites, however the one area it is really lacking is the reporting. You need to manually run the Get-StorageGroupCopyStatus -Server INITIALSERVER -StandbyMachine TARGETSERVER to find that your SCR is Healthy.</p>
<p>I&#8217;ve been playing around writing some simple PowerShell scripts today so I thought I would fix the reporting problem Microsoft haven&#8217;t.</p>
<p>I&#8217;ve written a simple PS script that gets the Status(Health), Replay Queue Length, Last Replayed Time and Last Full Backup Time and emails it to a specified address in a HTML table. Just use Task Scheduler to run this daily and you will receive the status of your SCR clusters.</p>
<p>You can download the script here <a href="http://mattlog.net/wp-content/uploads/2009/03/emailstoragegroupcopystatusreport.ps1">EmailStorageGroupCopyStatusReport.ps1</a></p>
<p>Or view the script below:</p>
<p>#Replace the PRIMARYSERVER attribute with your production mail server, and the SECONDARYSERVER with your SCR replica<br />
$MessageBody = Get-StorageGroupCopyStatus -Server PRIMARYSERVER -StandbyMachine SECONDARYSERVER | Select @{Expression={$_.StorageGroupName};Name=&#8221;Storage Group&#8221;}, @{Expression={$_.SummaryCopyStatus};Name=&#8221;Status&#8221;}, @{Expression={$_.ReplayQueueLength};Name=&#8221;Replay Que Length&#8221;}, @{Expression={$_.LastReplayedLogTime};Name=&#8221;Last Replayed Time&#8221;}, @{Expression={$_.LatestFullBackupTime};Name=&#8221;Last Full Backup&#8221;} | ConvertTo-Html</p>
<p>#Enter your mail server details<br />
$FromAddress = &#8220;FromAddress@YourDomain.com&#8221;<br />
$ToAddress = &#8220;ToAddress@YourDomain.com&#8221;<br />
$MessageSubject = &#8220;Exch07 SCR Status&#8221;<br />
$SendingServer = &#8220;MAILSERVER&#8221;<br />
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody<br />
$SMTPMessage.IsBodyHtml = $true<br />
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer<br />
$SMTPClient.Send($SMTPMessage)<br />
#Written by Matt Shadbolt<br />
#http://www.mattlog.net</p>
]]></content:encoded>
			<wfw:commentRss>http://mattlog.net/2009/03/12/auto-email-exchange-2007-storagegroupcopystatus/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Auto Email Exchange 2007 Mailbox Report</title>
		<link>http://mattlog.net/2009/03/12/auto-email-exchange-2007-mailbox-report/</link>
		<comments>http://mattlog.net/2009/03/12/auto-email-exchange-2007-mailbox-report/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 01:58:31 +0000</pubDate>
		<dc:creator>Matt Shadbolt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Email from PowerShell]]></category>
		<category><![CDATA[Email Report]]></category>
		<category><![CDATA[Exchange 2007]]></category>
		<category><![CDATA[Mailbox Size]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://mattlog.net/?p=120</guid>
		<description><![CDATA[Hi all. I&#8217;ve written this simple PowerShell script to output your user mailboxes, their total size and the item count &#8211; the script will then email the output to a specified account in a pretty HTML table format. Feel free to download the .ps1 file and run it as you wish. Remember that you need [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all. I&#8217;ve written this simple PowerShell script to output your user mailboxes, their total size and the item count &#8211; the script will then email the output to a specified account in a pretty HTML table format. Feel free to download the .ps1 file and run it as you wish.</p>
<p>Remember that you need to &#8220;Set-ExecutionPolicy RemoteSigned&#8221; in the Task Scheduler for the PS script to run correctly. Also, if you are going to run this PS script on a remote server you <em>may</em> need to add the MSExchange PS Snappin. To do this just add &#8220;Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin&#8221; to the first line of the script. You obviously need to change the mail server and recipient options.</p>
<p>Here&#8217;s the script download <a href="http://mattlog.net/wp-content/uploads/2009/03/emailmailboxsizereport.ps1">EmailMailboxSizeReport.ps1</a></p>
<p>And a break down of the script:</p>
<blockquote><p>#Firstly, get the users mailbox&#8230; ONLY objects that are UserMailbox and not HiddenFromAddressListsEnabled<br />
$MailboxUser = Get-Mailbox | Where {($_.RecipientType -eq &#8220;UserMailbox&#8221;) -and ($_.HiddenFromAddressListsEnabled -eq $False)}</p>
<p>#Secondly, get the mailbox statistics for the selected users. Some formatting also<br />
$MessageBody = $MailboxUser | Get-MailboxStatistics | Sort-Object TotalItemSize | Select DisplayName, ItemCount, @{Expression={$_.TotalItemSize.Value.ToMB()};Name=&#8221;MailboxSize MB&#8221;} | ConvertTo-html</p>
<p>#Finally, enter your mail server details<br />
$FromAddress = &#8220;FromAddress@YourDomain.com&#8221;<br />
$ToAddress = &#8220;ToAddress@YourDomain.com&#8221;<br />
$MessageSubject = &#8220;PowerShell Report Subject&#8221;<br />
$SendingServer = &#8220;YourMailServerAddress&#8221;<br />
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody<br />
$SMTPMessage.IsBodyHtml = $true<br />
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer<br />
$SMTPClient.Send($SMTPMessage)</p>
<p>#Written by Matt Shadbolt<br />
#http://www.mattlog.net</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://mattlog.net/2009/03/12/auto-email-exchange-2007-mailbox-report/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PowerShell: Remove Files based on date</title>
		<link>http://mattlog.net/2008/12/15/powershell-remove-files-based-on-date/</link>
		<comments>http://mattlog.net/2008/12/15/powershell-remove-files-based-on-date/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 03:34:30 +0000</pubDate>
		<dc:creator>Matt Shadbolt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Get-Date]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Remove-Item]]></category>

		<guid isPermaLink="false">http://mattlog.net/?p=85</guid>
		<description><![CDATA[I&#8217;ve had the need to remove a bunch of differential backup images from my backup server for a short while now &#8211; and thought this was the perfect opportunity to crack into powershell. I&#8217;m going to post the script and run through the important parts: dir C:\BACKUP -recurse -exclude SERVER1,SERVER2,SERVER3,SERVER4,SERVER1.IMG,SERVER2.IMG,SERVER3.IMG,SERVER4.IMG,FileClean.PS1 &#124; where { ((get-date)-$_.creationTime).days -ge [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had the need to remove a bunch of differential backup images from my backup server for a short while now &#8211; and thought this was the perfect opportunity to crack into powershell. I&#8217;m going to post the script and run through the important parts:</p>
<blockquote><p>dir C:\BACKUP -recurse -exclude SERVER1,SERVER2,SERVER3,SERVER4,SERVER1.IMG,SERVER2.IMG,SERVER3.IMG,SERVER4.IMG,FileClean.PS1 | where { ((get-date)-$_.creationTime).days -ge 1} | remove-item -force -recurse</p></blockquote>
<p>OK, piece by piece!</p>
<blockquote><p>dir C:\BACKUP -recurse<br />
This may look like a normal CMD prompt DIR, however it isn&#8217;t. Powershell uses DIR as an alias for Get-ChildItem which has a bunch of switches you can use. In this instance I wanted all files below the C:\BACKUP directory so I used -recurse</p>
<p>-exclude SERVER1,SERVER2,SERVER3,SERVER4,SERVER1.IMG,SERVER2.IMG,SERVER3.IMG,SERVER4.IMG,FileClean.PS1<br />
I then used the -exclude switch to ensure I don&#8217;t also delete the files that I need to keep. In my case I wanted to keep the current folder structure in tact so I excluded the SERVER1,SERVER2 (etc) directories from the Get-ChildItem command. I also didn&#8217;t want to remove the original base backup images (just the old differential images) so I&#8217;ve excluded them as well SERVER1.IMG,SERVER2.IMG. Finally, I&#8217;ve excluded the FileClean.PS1 file as this is the script file that would actually be running on a schedule.</p>
<p>where { ((get-date)-$_.creationTime).days -ge 1}<br />
I then piped the output of the Get-ChildItem into the where statement above. This line checks the Get-Date command on every file, and only returns the files that are older than 1 day. This is done by checking the $_.creationTime and only returning files that are greater than 1 (-ge 1)</p>
<p>remove-item -force -recurse<br />
Finally, I then pipe the output into the remove-item command. This will automatically delete the files that the first two commands produced. Note that you need to use the -recurse switch otherwise you will receive a bunch of confirmation prompts.</p></blockquote>
<p>While testing this script I suggest you use the -whatif switch at the end of the remove-item command. This will just output which files the remove-item will be deleting. Its very important you get the correct files the first time, otherwise you may delete all your files! You can now save the script as whatever you like and run it as a scheduled task.</p>
]]></content:encoded>
			<wfw:commentRss>http://mattlog.net/2008/12/15/powershell-remove-files-based-on-date/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Handy Download: PowerShell Default Alias List</title>
		<link>http://mattlog.net/2008/11/10/handy-download-powershell-default-alias-list/</link>
		<comments>http://mattlog.net/2008/11/10/handy-download-powershell-default-alias-list/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 00:02:04 +0000</pubDate>
		<dc:creator>Matt Shadbolt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Alias]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://mattlog.net/?p=76</guid>
		<description><![CDATA[Here&#8217;s a handy file for remembering all of the default PowerShell Alias commands. These save so much time when working in the shell. Print it out and tape to your cubicle for easy access! powershellalias]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a handy file for remembering all of the default PowerShell Alias commands. These save so much time when working in the shell. Print it out and tape to your cubicle for easy access!</p>
<p><a href="http://mattlog.net/wp-content/uploads/2008/11/powershellalias.txt">powershellalias</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mattlog.net/2008/11/10/handy-download-powershell-default-alias-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Opening Windows Powershell</title>
		<link>http://mattlog.net/2008/10/02/opening-windows-powershell/</link>
		<comments>http://mattlog.net/2008/10/02/opening-windows-powershell/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 23:50:11 +0000</pubDate>
		<dc:creator>Matt Shadbolt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://mattlog.net/?p=52</guid>
		<description><![CDATA[Quick tip: You don&#8217;t need to browse to Start &#62; Programs &#62; Windows PowerShell 1.0 &#62; PowerShell to launch a new PowerShell cmdlet &#8211; just open a Run box and type &#8220;powershell&#8221; Also, by default in Server 2008 the PowerShell console is coloured blue. This is for a good reason &#8211; it stops you from [...]]]></description>
			<content:encoded><![CDATA[<p>Quick tip:</p>
<p>You don&#8217;t need to browse to Start &gt; Programs &gt; Windows PowerShell 1.0 &gt; PowerShell to launch a new PowerShell cmdlet &#8211; just open a Run box and type &#8220;powershell&#8221;</p>
<p>Also, by default in Server 2008 the PowerShell console is coloured blue. This is for a good reason &#8211; it stops you from confusing the PowerShell from the older cmd console!<br />
If you&#8217;re installing PowerShell on Windows XP or Server 2003 the default cmdlet colour is black &#8211; I would suggest changing it to another colour for the reason mentioned.</p>
<p>You can download various versions of PowerShell from the following location &#8211; <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx">http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx</a> (To install PowerShell for Server 2008 you need to add it as a &#8220;Feature&#8221; from the Server Manager.)</p>
]]></content:encoded>
			<wfw:commentRss>http://mattlog.net/2008/10/02/opening-windows-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
