Hi, sorry 4 delayed replay, been away a few days. Howard the script is being run manually currently on either domain. They are just using it for the time being to verify machines that have been migrated. I will probably add it tonight to the old domain logon scripts. Not sure if I will be allowed to add to to the new domain yet but we will see. Otherwise it will be run manually.

Please don't be harshly critical about the code, I know I'm still a newbie but it does what I need it to do.

P.S. I removed the section which aborts if the script detects XP without any service pack. As seen with previous post it gives Error code 6.

Teflon
What do you mean? I don't get it...

Code:
 
Global $LogFile,$OldDomainName,$NewDomainName

;Configurable Section - Change according to your domain and log path, also note you must set the RootDSE for you AD domain in the 2 functions Checkuser, CheckComputer.
$LogFile = "\\hostname\INCOMING\MIGRATIONLOG.TXT"
$OldDomainName = "OLDDOMAIN"
$NewDomainName = "NEWDOMAIN"


;DO NOT MODIFY BELOW THIS LINE
;This is a Perfectly Migrated PC and User Account but is logging on to the wrong Domain
If @LDOMAIN = $OldDomainName AND IsMigrated($NewDomainName) = 1 AND CheckUser = 1 AND CheckComputer = 1
? "Logging onto " + @LDOMAIN + " Domain"
;? "Ignore - Debugging Purposes. Condition1"
? "User Account has been Migrated"
? "Computer Account has been Migrated"
? "Migration Success"
? "User logging on to incorrect domain"

If Open( 3 , $LogFile , 5 ) = 0
$x = WriteLine( 3 , "USERMIGRATED" + " " + @USERID + " " + "PCMIGRATED" + " " + @WKSTA + " " + "MIGRATIONSUCCESS" + " " + "Logging onto OLDDOMAIN" + " " + @DATE + " " + @TIME + @CRLF)
EndIf
Sleep 3
Endif

;This is a Perfectly Migrated PC and User Account and are logging onto the correct domain
If @LDOMAIN = $NewDomainName AND IsMigrated($NewDomainName) = 1 AND CheckUser = 1 AND CheckComputer = 1
? "Logging onto " + @LDOMAIN + " Domain"
;? "Ignore - Debugging Purposes. Condition2"
? "User Account has been Migrated"
? "Computer Account has been Migrated"
? "Migration Success"
? "User logging on to correct domain"

If Open( 3 , $LogFile , 5 ) = 0
$x = WriteLine( 3 , "USERMIGRATED" + " " + @USERID + " " + "PCMIGRATED" + " " + @WKSTA + " " + "MIGRATIONSUCCESS" + " " + "Logging onto NEWDOMAIN" + " " + @DATE + " " + @TIME + @CRLF)
EndIf
Sleep 3
Endif

;This is a failed Migration but User and Computer do exist in AD but logon to wrong domain
If @LDOMAIN = $OldDomainName AND IsMigrated($NewDomainName) = 0 AND CheckUser = 1 AND CheckComputer = 1
? "Logging onto " + @LDOMAIN + " Domain"
;? "Ignore - Debugging Purposes. Condition3"
? "User Account has been Migrated"
? "Computer Account has been Migrated"
? "Migration Failed!"
? "User logging on to incorrect domain"

If Open( 3 , $LogFile , 5 ) = 0
$x = WriteLine( 3 , "USERMIGRATED" + " " + @USERID + " " + "PCMIGRATED" + " " + @WKSTA + " " + "MIGRATIONFAILED" + " " + "Logging onto OLDDOMAIN" + " " + @DATE + " " + @TIME + @CRLF)
EndIf
Sleep 3
EndIf

;This is a failed Migration but User and Computer do exist in AD logon but are loggin on to new domain
If @LDOMAIN = $NewDomainName AND IsMigrated($NewDomainName) = 0 AND CheckUser = 1 AND CheckComputer = 1
? "Logging onto " + @LDOMAIN + " Domain"
;? "Ignore - Debugging Purposes. Condition4"
? "User Account has been Migrated"
? "Computer Account has been Migrated"
? "Migration Failed!"
? "User logging on to correct domain"

If Open( 3 , $LogFile , 5 ) = 0
$x = WriteLine( 3 , "USERMIGRATED" + " " + @USERID + " " + "PCMIGRATED" + " " + @WKSTA + " " + "MIGRATIONFAILED" + " " + "Logging onto NEWDOMAIN" + " " + @DATE + " " + @TIME + @CRLF)
EndIf
Sleep 3
EndIf

;This is a migrated computer but the user does not exist on AD
If IsMigrated($NewDomainName) = 1 AND CheckUser = 0 AND CheckComputer = 1
? "Logging onto " + @LDOMAIN + " Domain"
;? "Ignore - Debugging Purposes. Condition5"
? "User Account has Not been Migrated"
? "Computer Account has been Migrated"
? "Migration Success!"
? "User needs account created on AD"

If Open( 3 , $LogFile , 5 ) = 0
$x = WriteLine( 3 , "USERNOTMIGRATED" + " " + @USERID + " " + "PCMIGRATED" + " " + @WKSTA + " " + "MIGRATIONSUCCESS" + " " + @DATE + " " + @TIME + @CRLF)
EndIf
Sleep 3
EndIf

;This is a failed migration and the user also does not exist on AD
If @LDOMAIN = $OldDomainName AND IsMigrated($NewDomainName) = 0 AND CheckUser = 0 AND CheckComputer = 1
? "Logging onto " + @LDOMAIN + " Domain"
;? "Ignore - Debugging Purposes. Condition6"
? "User Account has Not been Migrated"
? "Computer Account has been Migrated"
? "Migration Failed!"
? "User logging on to incorrect domain"
? "User needs account created on AD"

If Open( 3 , $LogFile , 5 ) = 0
$x = WriteLine( 3 , "USERNOTMIGRATED" + " " + @USERID + " " + "PCMIGRATED" + " " + @WKSTA + " " + "MIGRATIONFAILED" + " " + "Logging onto OLDDOMAIN" + " " @DATE + " " + @TIME + @CRLF)
EndIf
Sleep 3
EndIf

;This is computer that hasn't been migrated but a user account exists for the user on AD
If IsMigrated($NewDomainName) = 0 AND CheckUser = 1 AND CheckComputer = 0
? "Logging onto " + @LDOMAIN + " Domain"
;? "Ignore - Debugging Purposes. Condition7"
? "User Account has been Migrated"
? "Computer Account has Not been Migrated"
? "Migration Not Started!"

If Open( 3 , $LogFile , 5 ) = 0
$x = WriteLine( 3 , "USERMIGRATED" + " " + @USERID + " " + "PCNOTMIGRATED" + " " + @WKSTA + " " + "MIGRATIONNOTSTARTED" + " " + @DATE + " " + @TIME + @CRLF)
EndIf
Sleep 3
EndIf

;This is computer that hasn't been migrated and a user account does not exist for the user on AD
If IsMigrated($NewDomainName) = 0 AND CheckUser = 0 AND CheckComputer = 0
? "Logging onto " + @LDOMAIN + " Domain"
;? "Ignore - Debugging Purposes. Condition8"
? "User Account has Not been Migrated"
? "Computer Account has Not been Migrated"
? "Migration Not Started!"
? "User needs account created on AD"

If Open( 3 , $LogFile , 5 ) = 0
$x = WriteLine( 3 , "USERNOTMIGRATED" + " " + @USERID + " " + "PCNOTMIGRATED" + " " + @WKSTA + " " + "MIGRATIONNOTSTARTED" + " " + @DATE + " " + @TIME + @CRLF)
EndIf
Sleep 3
EndIf

Function CheckUser()
Dim $Con ;(As ADODB.Connection)
Dim $Cmd ;(As ADODB.Command)
Dim $Rs ;(As ADODB.Command)
Dim $Root
;RootDSE for Domain - cannot be dynamic because you not logged onto AD
Dim $sDomain
;Configure RootDSE
$sDomain = "DC=gaming,DC=tsogosun,DC=com"
Dim $OU
Dim $Domain
Dim $sADsPath
Dim $sFilter
Dim $sAttribsToReturn
Dim $sDepth
Dim $strCount
Global $CheckUser

$strName = @UserID
If $strName = ""
? "No username was specified. "
Exit
EndIf

; Create ADO connection object for Active Directory
$Con = CreateObject("ADODB.Connection")
$Con.Provider = "ADsDSOObject"
$Con.Open ;"Active Directory Provider"

; Create ADO command object for the connection.
$Cmd = CreateObject("ADODB.Command")
$Cmd.ActiveConnection = $Con
$Domain = GetObject("LDAP://" + $sDomain)
$sADsPath = "<" + $Domain.ADsPath + ">"

; Build the filter element of the commandtext
If ($strName = "")
? "Error Nothing in Search String"
Exit
Else
$sFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=" + $strName + "))"
EndIf

; Build the returned attributes element of the commandtext.
$sAttribsToReturn = "sAMAccountName"

; Build the depth element of the commandtext.
$sDepth = "subTree"

; Assemble the commandtext.
$Cmd.CommandText = $sADsPath + ";" + $sFilter + ";" + $sAttribsToReturn + ";" + $sDepth

; Execute the query.
$Rs = CreateObject("ADODB.Recordset")
$Rs = $Cmd.Execute

$strCount = $rs.RecordCount
If ($strCount > 0)
$CheckUser=("1")

Else
$CheckUser=("0")

EndIf

If (@ERROR <>0)
? "Error - " + @SERROR
If Open( 3 , $LogFile , 5 ) = 0
$x = WriteLine( 3 , @USERID + " " + @WKSTA + " " + "An Error Occurred " + @SERROR + " " + @DATE + " " + @TIME + @CRLF)
EndIf
EndIf

EndFunction


Function CheckComputer()
Dim $Con ;(As ADODB.Connection)
Dim $Cmd ;(As ADODB.Command)
Dim $Rs ;(As ADODB.Command)
Dim $Root
;RootDSE for Domain - cannot be dynamic because you not logged onto AD
Dim $sDomain
;Configure RootDSE
$sDomain = "DC=gaming,DC=tsogosun,DC=com"
Dim $OU
Dim $Domain
Dim $sADsPath
Dim $sFilter
Dim $sAttribsToReturn
Dim $sDepth
Dim $strCount
Global $CheckComputer

$strName = @WKSTA
If $strName = ""
? "No computer name was specified. "
Exit
EndIf

; Create ADO connection object for Active Directory
$Con = CreateObject("ADODB.Connection")
$Con.Provider = "ADsDSOObject"
$Con.Open ;"Active Directory Provider"

; Create ADO command object for the connection.
$Cmd = CreateObject("ADODB.Command")
$Cmd.ActiveConnection = $Con
$Domain = GetObject("LDAP://" + $sDomain)
$sADsPath = "<" + $Domain.ADsPath + ">"

; Build the filter element of the commandtext
If ($strName = "")
? "Error Nothing in Search String"
Exit
Else
$sFilter = "(&(objectCategory=computer)(objectClass=computer)(name=" + $strName + "))"
EndIf

; Build the returned attributes element of the commandtext.
$sAttribsToReturn = "name"

; Build the depth element of the commandtext.
$sDepth = "subTree"

; Assemble the commandtext.
$Cmd.CommandText = $sADsPath + ";" + $sFilter + ";" + $sAttribsToReturn + ";" + $sDepth

; Execute the query.
$Rs = CreateObject("ADODB.Recordset")
$Rs = $Cmd.Execute

$strCount = $rs.RecordCount
If ($strCount > 0)
$CheckComputer = 1
Else
$CheckComputer = 0
EndIf

If (@ERROR <>0)
? "Error - " + @SERROR
If Open( 3 , $LogFile , 5 ) = 0
$x = WriteLine( 3 , @USERID + " " + @WKSTA + " " + "An Error Occurred " + @SERROR + " " + @DATE + " " + @TIME + @CRLF)
EndIf
EndIf

EndFunction

Function IsMigrated($NewDomain)
If @Domain = $NewDomain
$IsMigrated = 1
Else
$IsMigrated = 0
EndIf
EndFunction