Archive for October, 2011

Script to configure static ports on Exchange Server 2010

There is nothing new about this. If you have been reading about Exchange Server 2010 or have it deployed with hardware load balancer, chances are, you have read how to configure static ports on Exchange Server 2010 on TechNet Social wiki for Exchange 2010. Chances are that you have also used my script (referenced in the post above) to set static ports on your servers. Lastly, chances are that you have read all about it on my previous post here.

If so, why am I even talking about it today?

Well, if you haven’t noticed a few things already, the way you change ports is different in RTM and SP1. My script didn’t account for SP1 originally when it was written. Was SP1 even existed then?

The other reason is my nature of always learning something and making things better! I noticed how my code was inefficient now that I know a few more things about PowerShell (yeah that’s not funny). I decided to write it more efficiently and that basically meant a complete overhaul of my old script.

The new script is now more user friendly! It uses cmdletbinding and comment based help. It means, for you as a user, you can just type:

Get-Help Set-StaticPorts.ps1 –examples

or

Get-Help Set-StaticPorts.ps1 –Full

The script now validates parameters using ValidateRange and ValidateScript. I think that’s cool! It also uses 59531 and 59532 by default now. How about using recommended ports instead of random ones I used in my previous script? I think that’s even more cool!

The script uses all the right write-* cmdlets now instead of write-host. So now you can use tee-object and won’t end up with empty output file. Yes you loose cool colors I used with write-host but hey, you are trying to set ports on your Exchange Server 2010. For colors you would go see Macy’s Fireworks on New Year, right? Smile

Oh and last but probably the most important change is inclusion of –auto and –whatif functionality!

-WhatIf is obvious. Script will tell you what it is doing without actually making any changes.

-Auto will automatically find all your Exchange 2010 CAS servers and Exchange 2010 Mailbox servers that are hosting Public Folders. It will then change ports on CAS Server for RPC CA service and Exchange AB service. On Mailbox servers it will only change RPC CA ports as Exchange AB service doesn’t exist on Mailbox only role.

If you combine all this with –Force, you can also silence the script. It won’t ask you for any confirmation and will change ports you specify (or use defaults) and restart the services! Isn’t that awesome!

So go download the script from here: Set-StaticPorts.ps1 and give it a go. As always, let me know if you find any issues and I will be happy to fix it.

Originally posted at http://blogs.technet.com/bshukla

Share

PowerShell script to edit remote registry

Did you ever wanted to modify your registry or add a key/value pair to registry? Wished there was a script to help you do that? Even better, wished it can run remotely without PowerShell WinRM listener configured on target server?

I had custom script that would modify certain registry entry but it was inflexible and in my recent rewrite of another script, I wanted more flexibility. So out of necessity, I decided to rewrite my registry script  and made it independent script with lot of flexibility.

Using this script, you can now run it like this:

.\Set-RemoteRegistry.ps1 -Key SYSTEM\CurrentControlSet\services\AudioSrv\Parameters -Name ServiceDllUnloadOnStop -Value 1 -Type DWord

If you want to suppress prompts, you can use –Force parameter like this:

.\Set-RemoteRegistry.ps1 -Key SYSTEM\CurrentControlSet\services\AudioSrv\Parameters -Name ServiceDllUnloadOnStop -Value 0 -Type DWord –Force

This script is also a good example of cmdletbinding and support of whatif. I still think use of Whatif in scripts has its limitations as apprarent in this script (without adding more code to it to work around that limitation).

The script is also a good example of how you can use parameter validation right in the parameter declaration. This way you can avoid if..then code blocks to validate parameter inputs. What a wonderful discovery, I gotta thank PowerShell team for this.

So go ahead, get the script Set-RemoteRegistry.ps1 here and if you find any issues, let me know. Have Fun!

Originally posted at http://blogs.technet.com/bshukla

Share