/build/static/layout/Breadcrumb_cap_w.png

K3.6 - Post Install Task to Join Domain Loops

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   [ + ] Show comments

Answers (1)

Posted by: SMal.tmcc 9 years ago
Red Belt
0

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 DOMAIN_JOIN_IF_JOINED   = 32
Const JOIN_UNSECURE           = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET        = 256
Const INSTALL_INVOCATION      = 262144

If WScript.Arguments.Count < 3 or WScript.Arguments.Count > 4 Then
  WScript.Quit
Else
  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, _
                                                JOIN_DOMAIN+ACCT_CREATE)  
 

 

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

 

 


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

    http://www.itninja.com/blog/view/k2-advisor - SMal.tmcc 9 years ago
  • 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. - hutcha4113 9 years ago
    • checking the box will cause a reboot after that task. - SMal.tmcc 9 years ago

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ