Having a strange issue with one of my Post install tasks, which joins the computer to the domain.  We are using Powershell - and had it working fine on version 3.5.

My original problem in 3.6 was running via CMD - which I have changed to a Batch File.  The command I am using to call the PS Script:

cmd.exe /c powershell -nologo -executionpolicy bypass -noprofile -file ".\domain.ps1"

It does call the script, and joins the computer to the domain - so that part works.  However after reboot it tries to run this task again - and again - and again.  The only way I can get it past this task is to be in front of the PC - and attempt to close it before it runs.

This is the only task that it happens to. 

Below is the PS Script in case it is something inside it:


$username = “Account We Use”
$password = ConvertTo-SecureString “Password Used” -AsPlainText -Force
$myCred = New-Object System.Management.Automation.PSCredential $username, $password

Add-Computer -DomainName smdhu.net -Credential $mycred; restart-computer

0 Comments   [ - ] Hide Comments


Please log in to comment

Answer this question or Comment on this question for clarity



Try taking the restart out of your ps script, this could be happening since ps is rebooting the system, the kengine does not see this batch task as completed and reruns it.  You can check the "reboot required" box on the task to cause the reboot or just make this one of your last tasks and left the kengine reboot happen prior to cleanup.

You can also switch to the join domain vbs script instead

upload this vbs as a dependancy, use a bat task and call

cscript /b join_domain.vbs domainname domainuser password

cut and paste below for vbs file:

Const JOIN_DOMAIN             = 1
Const ACCT_CREATE             = 2
Const ACCT_DELETE             = 4
Const WIN9X_UPGRADE           = 16
Const JOIN_UNSECURE           = 64
Const DEFERRED_SPN_SET        = 256
Const INSTALL_INVOCATION      = 262144

If WScript.Arguments.Count < 3 or WScript.Arguments.Count > 4 Then
  strDomain   = WScript.Arguments.Item(0)
  strUser = WScript.Arguments.Item(1)
  strPassword = WScript.Arguments.Item(2)

'set DNS IP address
  If WScript.Arguments.Count = 4 Then
    strDNSIP = WScript.Arguments.Item(3)
    Set objShell = CreateObject("WScript.shell")
    objShell.Run "netsh int ip set dns  ""local area connection"" static "& _
                  strDNSIP &" primary",0,0
  End If

End If

Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName

Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
                             strComputer & _
                             "\root\cimv2:Win32_ComputerSystem.Name='" _
                             & strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
                                                strPassword, _
                                                strDomain & "\" & strUser, _
                                                NULL, _


I went and put this file in my images so all I need to do is call this is my post script bat like this.

start /wait cscript.exe c:\windows\w2d\join_domain.vbs acad.tmcc.edu user password



Answered 06/06/2014 by: SMal.tmcc
Red Belt

  • you may want to try the K2 advisor and see if it detects any problems

  • Ok. I removed the restart from the script, and checked off "Restart Required". I was looking at both those settings anyway so figured I would try it.

    Am I correct than that selecting "Restart Required" tells the task engine to reboot the PC? I was wondering about that. If that is the case I will delete all my reboot tasks.
    • checking the box will cause a reboot after that task.
Please log in to comment