I was recently checking out the KKE archive and saw this being referred to and was hoping someone could pass this along

Answer Summary:
0 Comments   [ - ] Hide Comments


Please log in to comment

Community Chosen Answer



I use this. This will attempt to join a specific OU. If the record already exists in that OU it will join the domain.

$domain= "domain.org"

$password= "<user password>" | ConvertTo-SecureString -asPlainText -Force

#enter user account that will be used to join domain

$user= "$domain\<user>"

$cred= New-Object System.Management.Automation.PSCredential($user,$password)

#edit for OU path

$oupath = 'OU=Laptops,OU=Workstations,DC=domain,DC=ORG'

#add computer to OU

Add-Computer -domainname $domain -oupath $oupath -Credential $cred -ErrorAction silentlycontinue

#add computer to domain

Add-Computer -DomainName $domain -Credential $cred
Answered 09/17/2013 by: dugullett
Red Belt

  • Save this as .ps1. Upload it as an app post install. Use this as your command line (assuming you name it domain.ps1).

    powershell.exe -nologo -executionpolicy bypass -noprofile -file domain.ps1
    • I just tried this on the K2000 version 3.6.98680 and it fails with an error of "The system cannot find the file specified".

      Do I need to zip up powershell.exe with the domain.ps1 file? Do I need to put domain.ps1 in " "?
      • Zip it up w/ a .bat file that has that same command line. Add it to a post install, and enter then name of the .bat in your command line.
      • Zip what up? The powershell.exe and the .bat file, or just the command in a bat file?
      • You should save this powershell script as a .ps1. The create a .bat file that has the command line below. Zip those two up together.

        powershell.exe -nologo -executionpolicy bypass -noprofile -file <name of your script>.ps1
      • I added this in a zip file with the domain.ps1 file I edited and the command worked. However, the machine was not moved to the OU specified in the script. The machine remained in the OU it was in prior to running the script.
      • That's how I have it set.
      • So when mr_jimmyjames said "Just to clarify, "if the record DOES exist already", it will still join the intended OU?" the answer is no, it will not.
      • Correct. If you see my reply to that question. If it exists already in an OU it will rejoin that one. If not, it will join the one you specify.
      • I also see in your reply where you said "Yes." when you should have said "No."... This was a waste of time for me because of that.
      • Sorry. When I said "Keeping the existing record in the OU" I probably should have said "Keeping the existing record in the OU"?
      • No that part is fine, but you may want to learn what yes and no mean.
  • Just to clarify, "if the record DOES exist already", it will still join the intended OU?
    • Yes. If it's a brand new machine it will join the OU first. If it's a machine being reimaged it will try to join the OU, realize there's a record there, and then just join the domain. Keeping the existing record in the OU.
  • Cool, thanks!
  • Would anyone know how to couple this with wsname to get the PC named/renamed and joined to the domain?
    • I would use WSName as a separate post install ran before this one. You may have to add a reboot in between the two using the post install task converter. I personally do not use the WSNAME anymore since our naming standards are very unique.

Please log in to comment
Answer this question or Comment on this question for clarity



I use the join domain vbs script provided by kace to join my machines to the domain, but here are some PS examples



Answered 09/17/2013 by: SMal.tmcc
Red Belt

  • Thanks, I do appreciate it.
  • I read of few of your posts regarding imaging w/k2000 and would like to say well done. That said, I was hoping you can offer some guidance/assistant/wisdom, as I'm new to the imaging process, I've been using mostly scripted installs. I'm sort of pressed for time, otherwise, I would watch the KBE's, read the tutorials, of course ITNinja, etc... My email is jharting96@gmail if you are willing to assist a n00b that is just starting out and in a hurry, if not, I understand.. Thanks in Advance
    • I post my email on the site under my profile to help other's. I have had others email my gmail account and we opened a chat session to help walk them though a problems quickly and send them some of my support files for imaging. Just got back from 10 days supporting the Reno Air Races so still getting caught up, I am on PST and should have time tomorrow to get in touch with you around 7:30-8:00 am my time.
Please log in to comment