What Good is PowerShell?
One of my favorite powershell guru’s Michael Pope (who also runs the Triangle SBS Group) posted this handy note. So of course I stole borrowed it from him to share it with you.
As always use at you own risk, ymmv
I know some of you may still be wondering what good PowerShell is for. It’s relatively new and shiny but what can it do?
Someone on the Kaseya forums was asking how to script the update of a MULTI_SZ registry value because they wanted to push out an update related to this post http://blogs.technet.com/sbs/archive/2008/07/17/some-services-may-fail-to-start-or-may-not-work-properly-after-installing-ms08-037-951746-and-951748.aspx
This is something I had been meaning to script so I took some time last night and put it together. This is just an example of something that’s simple to do with PowerShell that is very difficult to do otherwise.
For those of you that are interested, save the following to an Update-ReservedPorts.ps1 script file in Notepad:
$NP=”1645-1646″,”1701-1701″,”1812-1813″,”2883-2883″,”4500-4500″
$P=”HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters”
$RP=(Get-ItemProperty -Path $P -Name “ReservedPorts”).ReservedPorts
$RP=$RP+=$NPSet-ItemProperty -Path $P -Name “ReservedPorts” -Value $RP
RTP Computer Services, Inc.
105 West NC Highway 54
Suite 265
Durham, NC 27713
Phone: 919.806.8845
Fax: 800.853.3365
Email: michael AT rtpcomputer.com
Web: http://www.rtpcomputer.com/

Then, run it within PowerShell and you’re done. I tried scripting this with REG.EXE and it was very difficult because this is a MULTI_SZ registry value.

August 19th, 2008 at 9:46 pm
This assumes that ReservedPorts already exists:
for /f “tokens=3″ %i in (’reg query HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters /v ReservedPorts’) do reg add HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters /v ReservedPorts /t REG_MULTI_SZ /d %i1645-16461701-17011812-18132883-28834500-4500 /f
Otherwise you just do a straight reg add.