Monthly Archives: March 2011

If any of you have ever created a file in the PowerShell ISE and then wondered why it doesn't look right when you open it in some other editor, or try to run it, you've just run into a "feature" that I wish were not the default--New files are saved as Unicode files. There's no problem with you're working with an existing ASCII file, the ISE will preserve the format. But if you're creating a new file, it saves as Unicode. Now this has always annoyed me, but I never really did anything about it, just worked around it when I got hit with it. But the other day I came across an old blog post from Doug Finke, a fellow PowerShell MVP. He adds the following line to his ISE $profile:

In my environment, with a virtualized SBS 2011 Standard, there are occasionally Microsoft Exchange 2010 services that don't properly restart if there has been an abrupt power failure on the Hyper-V host. (Don't ask.)

Now, of course, the first time this happened, I just logged in to the server and started the services. But when it happened again, it's time to write a script. And it was a fun script, since it uses WMI and PowerShell remoting and other fun stuff.

# Script to start Exchange services on SBS 2011 Server after power failure # # Accepts a parameter of the exchange server name, but defaults to SRV2 if none entered # Assumes you are logged in to the domain with Domain Admin credentials # # Created: 14/03/2011 by Charlie # ModHist: 15/03/11 -switched to using WMI in the session to get StartMode # # param ($ExchSrv = "SRV2" )

# first, open a session to the Exchange server $srv = New-PSSession $ExchSrv

The if statement in there is to prevent an error if all the services are running. Of course, for this script to work as it's written, you'll need to run it from a workstation in the SBS domain, and you'll have to enable PowerShell remoting on both the server and the client. If you haven't done that yet, I've posted a quick setup guide on TechNet.

I've posted this script up to the Microsoft Script Center, so if you have comments or suggestions to improve it, please comment there.