Changing PostgreSQL port using command line
Since you're on Windows and are probably starting PostgreSQL as a Windows service, you'll need to edit postgresql.conf (inside your data directory) to set the new port there, then restart the postgresql service using the Services control panel or (as an Administrator) the net service command.

You can use a programmatic text editing tool to change postgresql.conf if you need to automate this. On a Linux/unix box you'd use a tool like sed or awk, but on Windows I imagine you'll be using VBS, powershell, or an add-on tool like Perl.

You'll need to change the connection settings in tools like PgAdmin-III to use the new port.

If you were starting PostgreSQL manually using pg_ctl you could set the PGPORT environment variable or pass a config option on the command line. This won't work when you're launching it as a Windows service.