Change computer names remotely using NETDOM on Windows XP

I got this familiar error message earlier when trying to change the computer name of a Windows XP machine:

“Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again”

To get around this, I used the following netdom command from my PC (replace capital words with your own):
netdom renamecomputer OLDCOMPUTERNAME /newname:NEWCOMPUTERNAME /userD:domain\administrator /passwordd:ADMINPASSWORD /usero: domain\administrator /passwordo: ADMINPASSWORD  /reboot:10
This renamed the computer and rebooted the little sucker in 10 seconds.

Read more about the netdom command here.

Using data and time in batch files

If you need to use the current date and time within batch files, I find this code very useful:

%date:~-4,4%-%date:~-7,2%-%date:~-10,2%#%time::=-%

For instance, say you’re moving or copying a file somewhere and you want to rename it with today’s date and time, you could set a filename variable like so:

set filename=%date:~-4,4%-%date:~-7,2%-%date:~-10,2%#%time::=-%

This would output a string with the format yyyy-mm-dd#hh-mm-ss.ms (ms being micro-seconds):

2012-01-19#13-04-27.17

To add the computer name to the string use:

%computername%#%date:~-4,4%-%date:~-7,2%-%date:~-10,2%#%time::=-%

How to find out which servers hold the FSMO roles in your forest/domain

Just a quick tip on finding which servers hold the Flexible Single Master Operations(FSMO) roles.
Enter the following at the command prompt from any Domain Controller:

for %x in (schema name infr pdc rid) do dsquery server -forest -hasfsmo %x

An explanation of the roles and how to transfer them can be found here: http://support.microsoft.com/kb/324801

Edit: An even quicker way is to type:

netdom query fsmo