PreMigMachChk - Pre-Migration Machine Check v1.3

Copyright (c) 2003-2007 Gerald W. Gaston

Revision History:
v1.0 - Created with hardcoded values
v1.1 - Added /A, /C, /T,  and /W switches
v1.2 - Added /D, /I, /P, /Q, and /V switches
v1.3 - Added /F and /R switches

Changes after v1.1 have been primarily to make PreMigMachChk more useful outside of migrations.

------------------------------------------------------------------------------
Terms of Use:

THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED. USE AT YOUR OWN RISK.

YOU MAY NOT DISTRIBUTE PREMIGMACHCHK WITHOUT THE EXPRESS WRITTEN PERMISSION OF GERALD W. GASTON.
------------------------------------------------------------------------------

PreMigMachChk is a simple console utility that can be used to verify that a PC is ready to be migrated using other utilities, such as Microsoft's Active Directory Migration Tool (ADMT). PreMigMachChk can also be used to verify the general availability/access of a remote host.

PreMigMachChk was created in 2003 due to frustrations encountered when trying to quickly migrate PCs from many NT resource domains to a new AD domain using ADMT v2. PreMigMachChk performs a few checks against a remote PC to verify that it is ready to have the ADMT agent deployed to it. ADMT v3 (in beta still as I write this) I'm told, now has a pre-check feature that may eliminate the need to use PreMigMachChk (at least for the task that it was originally designed for). I've only read a little bit about this new pre-check feature, so I can't make a direct comparison. Even if PreMigMachChk is no longer needed for AD migrations, you may still find it useful in batch files (by using the /Q switch and checking errorlevel) as an initial check before attempting to do other things.

PreMigMachChk verifies the following ADMT Agent requirements are met:
1. The computer to be migrated (client) must be running.
2. * Client must have 15 MB of free disk space for the agent and agent log files.
3. The ADMIN$ share must exist on the client computer.
4. Remote registry access must be enabled on the client computer.
4. NetBIOS must be enabled on the client computer.  
5. The Server service must be running on the client computer.
7. The account performing the ADMT agent installation must be a local administrator on the client computer to be migrated.

* It does this check only against the ADMIN$ share. The amount checked for can be changed with the /F switch, and the check can be disabled completely with the /D switch (or using /F 0).

I finally found a little time to update PreMigMachChk to make it useful to the general public. It was initially hard coded for my specific environment, and was short a few switches. For our migrations we only wanted to target W2K or greater PCs (as NT4 was not going to be allowed to remain on the wire), and since PreMigMachChk was only called from a wrapper batch file that pinged the PC first, there as no need for PreMigMachChk to ping the target PC itself. The /A (allow NT4) and /P (ping host) switches were added to address these shortcomings. A companion batch file (PreMach.cmd) is also provided in the same zip file as PreMigMachChk. Please let me know if you find it useful.


Syntax:
------------------------------------------------------------------------------
PreMigMachChk /M (HostName | IP_Address) [/C Current_DOMAIN] [/T Target_DOMAIN]
              [/F nnn] [/D] [/I] [/W] [/A] [/P] [/R] [/V | /Q]

Use PreMigMachChk to help verify that a remote host is ready for AD migration, or to verify general availability/access of a remote host. Exits with error code 0 if successful. Host and domain names should be NetBIOS names. 

/M (required): Specify the host to check
/C (optional): Specify the expected CURRENT domain of the host
/T (optional): Specify the TARGET domain we are migrating to
/D (optional): Disable check for free space (15MB default) on admin$ share
/F (optional): Specify free space (MBs) needed on admin$ share (15MB default)
/I (optional): Ignore NetBIOS name mismatch
/W (optional): Workstation Only: Exclude (fail) hosts that are servers
/A (optional): Allow NT4: Include (pass) hosts running NT4 OS
/P (optional): Ping host to verify online
/R (optional): Try connecting with DNS name or IP Address if NetBIOS name fails
/V (optional): Verbose: Shows additional information (leading ! in output)
/Q (optional): Quiet: Set errorlevel but display nothing (except syntax errors)


Notes:
------------------------------------------------------------------------------
Use the /F switch to check for a different amount (def is 15MB) of disk space on the ADMIN$ share drive. Amount specified is in MBs and must be a whole number less than or equal to 2048. A value of 0 is the same as using the /D switch.

Host and domain names should be NetBIOS names. If a FQDN is passed it will be truncated to the leftmost label up to the first 15 characters. To relax this slightly for the hostname, you can use the /R switch.  Using this switch will cause PreMigMachChk to attempt to connect with exactly whatever you passed via the /M switch if the connection with the NetBIOS name fails. So if you give it an IP Address, it will resolve that to the hostname. If a connection via NetBIOS hostname fails, it will then try the IP Address. Same idea for a DNS name. The /R switch was added for general use, and is not intended for pre-migration checks. 

PreMigMachChk.exe /M 192.168.1.106 /d /a /p /R /v
 + Resolved IP address to: mywebserver.mydom.com
 + Host UP. Successfully pinged: 192.168.1.106
 ! Retrying NetWkstaGetInfo call with IP Address: 192.168.1.106
 + NetBIOS name matches.
 + Host in domain: WEBDEV
 ! OS version: 5.2
 ! OS comment: Dev WEB/SQL Server
 ! ROLE: non-DC server
 ! Active sessions: 20
 + Admin$ share exists.
 + Connected to remote registry.
 + SERVER role.
 + W2K or greater OS.

PreMigMachChk.exe /m someserv.somedom.com /a /p /v /R
 + Resolved hostname to: 192.168.1.109
 + Host UP. Successfully pinged: 192.168.1.109
 ! Retrying NetWkstaGetInfo call with: SOMESERV.SOMEDOM.COM
 - Can not access. NetWkstaGetInfo call failed.


Exit codes:
------------------------------------------------------------------------------
0   - All checks were successful.

1   - Could not resolve hostname or host offline.

2   - Can not access. Non-NT host or locked down.

4   - NetBIOS name does not match.

8   - Target PC is already in the targeted domain (if specified with /T switch).
       -OR-
      Target PC is not in the expected current domain (if specified with /C switch).

16  - Can not access Admin$ share, or it has less than 15MB free.
      You can disable the 15MB free check by using the /D switch.

32  - Server detected. This can only occur if you have used the /W switch.

64  - OS version is less than expected. Use /A to allow NT4 PCs.

128 - Could not access remote registry.

Note: The exit/error/return code set by PreMigMachChk can be a combination of the above. Please see the example wrapper batch file (PrepMach.cmd) on how to handle this.

In this example we are wanting to ping the host (/P), provide verbose output (/V), and are expecting the host to be a workstation (/W) running W2K or greater (absence of /A):

PreMigMachChk.exe /M myntsrvr /P /V /W
 + Resolved hostname to: 192.168.1.101
 + Host UP. Successfully pinged: 192.168.1.101
 + NetBIOS name matches.
 + PC in domain: RESOURCE
 ! OS version: 4.0
 ! OS comment: El Paso BDC
 ! ROLE: Domain Controller
 ! Active sessions: 2
 + Admin$ share exists and has greater than 15MB free.
 + Connected to remote registry.
 - SERVER role.
 - NT4 OS.

echo %errorlevel%
96

96 comes from:
32  - Server detected. This can only occur if you have used the /W switch.
64  - OS version is less than expected. Use /A to allow NT4 PCs.

The above run would have exited with a error code of 0 if the /W switch (workstation only) was removed, and the /A switch (allow NT4) was added.

More Examples...

See PostMigMachChk for another simple utility to run after migration is complete.


Copyright 2004-2007 Gerald's Tools