Posts Tagged ‘PowerShell’

Installing Enterprise Vault 9 Pre-Requisites via PowerShell

This might come in handy for some. It can be executed from PowerShell running as Administrator.

Import-module ServerManager
Add-WindowsFeature MSMQ-Server, NET-Framework-Core, Web-Server, Web-Static-Content, Web-Default-Doc, Web-Dir-Browsing, Web-Http-Errors, Web-Http-Redirect, Web-Asp-Net, Web-NET-Ext, Web-ASP, Web-ISAPI-Ext, Web-ISAPI-Filter, Web-Http-Logging, Web-Log-Libraries, Web-Request-Monitor, Web-Http-Tracing, Web-Basic-Auth, Web-Windows-Auth, Web-Filtering, Web-IP-Security, Web-Stat-Compression, Web-Mgmt-Console, Web-Scripting-Tools, Web-Mgmt-Service, Web-Metabase, Web-WMI, Web-Lgcy-Scripting, Web-Lgcy-Mgmt-Console, RSAT-Web-Server

Automatically Fixing FailedAndSuspended Exchange 2010 Databases with PowerShell

No Comments » Written on August 18th, 2010 by
Categories: Exchange, PowerShell
Tags: , ,
Another quick script, this one finds all databases located on Exchange 2010 servers with a status of ‘FailedAndSuspended’ and then reseeds them. Since this scripts makes changes to the systems, instead of just reading information, all activities are logged via PowerShell’s transcript feature. You’ll need to change the path in the 5th line of the script to reflect an actual location on your system.
Note that there are other options besides a reseed, this just makes the most sense the majority of the time.

add-pssnapin *0* -ErrorAction SilentlyContinue
$startstring="Start script run at:  "
$startendtime=date
$startannounce=$startstring+$startendtime
Start-Transcript -Append -Force -Path 'C:\<path>\DBHealthFix.log'
$startannounce
#gets list of mailboxservers, locates 2010 servers, gets db copy status, finds copies that are failed, updates failed copies
$mailboxservers = get-mailboxserver | get-exchangeserver | ?{$_.IsE14OrLater -eq 'True'}
foreach ($mailboxserver in $mailboxservers){
get-mailboxdatabasecopystatus -Server $mailboxserver.name | ?{$_.Status -like 'FailedAndSuspended'} | update-mailboxdatabasecopy -deleteexistingfiles -confirm:$false
}
stop-transcript

Here are some screenshots of what happens along the way:

The script shown in the first and last screenshot is available here.

Checking Exchange 2010 Database Health with PowerShell

3 comments Written on August 18th, 2010 by
Categories: Exchange, PowerShell
Tags: , ,

Just a quick script that checks your database health. Anything besides ‘Healthy’ or ‘Mounted’ should probably be investigated. :)

Add-PSSnapin *0* -ErrorAction SilentlyContinue
$mailboxservers = get-mailboxserver | get-exchangeserver | ?{$_.IsE14OrLater -eq 'True'}
$A = (get-host).UI.RawUI
$A.WindowTitle = "Database Health Check"
$B = $A.windowsize
$B.width = 110
$B.height = 30
$A.WindowSize = $B
while ($true) {cls; foreach ($mailboxserver in $mailboxservers){Get-MailboxDatabaseCopyStatus -Server $mailboxserver.name | ft -AutoSize Name,*Status,ContentIndexState,CopyQueueLength,ReplayQueueLength} ;sleep 5}

This it the output, refreshed every 5 seconds:

An example of when databases are actually doing something:

Populating Mailboxes with Dummy E-Mail

No Comments » Written on January 14th, 2010 by
Categories: Exchange, PowerShell
Tags: , ,

I’ve been looking around for some good ways to flesh out an Exchange lab to test some migration scenarios. I’ve gotten a lot of good advice from people on good ways to do this, but I really wanted something simple and elegant. Here’s what I settled on:

The Concept

Ed Crowley, MVP and all-around good guy (I suspect, since I’ve never actually met the guy), suggested that I just simply use a script to build a bunch of RFC-822 formatted files with the *.eml extension and then dump them in the Transport folder. This will cause Exchange 2007 to look at them and deliver them to the mailbox that they need to go to. I remember using some hackery like this back when I was manually looking at spam on an Exchange 2003 box. I would gather up all the false positives and resubmit them to the dumpster for delivery. The real benefit of this method is that I can use PowerShell to generate those files a LOT more quickly than I can figure out a script to generate the actual SMTP submission.

The Script

Once I did the research on what the RFC-822 format actually requires, here’s the PowerShell script I wrote to generate mail messages for the three test mailboxes:

<#

This is a script to generat a bunch of *.eml files and dump them in the transport directory of Exchange

Tim Robichaux

1/14/2010

EMLGenerationScript.ps1

#>

$Users = @();

$Users = "TimTest1","TimTest2","TimTest3";

$Body = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam id mauris sit amet nisl <snip> rutrum tempus, enim nisi sed.";

foreach ($User in $Users) {

$Counter = 1;

While ($Counter -lt 100){

$To = "To: " + $User + "@testdomain.com";

$From = "From: " + "tim@testdomain.com";

$Subject = "Subject: " + "This is test message `#$Counter";

$GUID = [system.guid]::newguid();

echo $From $To $Subject "`n" $Body | out-file "C:\Program Files\Microsoft\Exchange Server\TransportRoles\Pickup\$GUID.eml" -Encoding ASCII;

$Counter += 1;

}

}

The Outcome

It looks like the server that I’m populating is a VM, so I’ve totally swamped the transport service as it’s taking quite a while to deliver the messages. Another interesting thing is that it looks like it’s delivering them based on the order of the GUID, rather than the timestamp, so they’re showing up in all sorts of odd order.

I have to label this project as a success so far. I wanted to be able to generate some content quickly and I have to say that the hour I’ve spent getting this straight was worth it, balanced on the time it would have taken to populate messages by hand.

Lessons Learned and Future Revisions

There are a couple of really important things I learned from this. First off, the cmdlet “out-file” defaults to the system default. This means that if you are using it for generating some raw text, you have to explicitly set “ASCII” or whatever you need. I’ve run into this gottcha before, but it’s no less frustrating. Another thing that I learned from this is that older versions of PowerShell don’t always like comments and things like that. It’s often quite confusing about what you can do on a given system with the version of PowerShell that’s installed.

In future revisions, I want to build this into a user account generation script so that at the time of generation, I create the user, generate the mailbox and then populate it. Another thing that I would like to do is set up an array or pool of “From” addresses to give a little bit variety. Also a nice feature would be to add a “-FromFile” switch that would allow me to populate a bunch of the variables from a config file.