/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


K2000 Computer name generation, Domain join and Computer Object creation in correct OU

12/01/2015 2074 views
Hi,

I think this is probably a pretty normal task request for the Kace, I see lots of similar questions, but no single unified answer or solution anywhere.

I want to assign a computer name, I have read the WSScript can do this, not sure of all the options yet, but then I want to join the computer to the domain and create the computer object in the correct OU if the computer account does not exist already.  


Answer Summary:
0 Comments   [ + ] Show comments

Comments


Answer Chosen by the Author

1
Hello,

to set the computer name to the desiderated one you can use Get/Set Computer name utility or WSNAME.

Then to join the device to the domain and put it in a specific OU you can use a slightly modified version of the post-installation task Example: Join Domain that you find by default in the K2000.

The script uses the JoinDomainOrWorkgroup method of the Win32_ComputerSystem class.
One of the parameters that you can pass to the method is the OU as documented here: https://msdn.microsoft.com/en-us/library/windows/desktop/aa392154(v=vs.85).aspx

The script Example: Join Domain does not set this parameter and send a NULL value instead.
I modified it a little bit as an example and I tried it with success in a scripted installation:

'This script accepts 4 parameters: 3 are mandatory and the last one is optional'USAGE:'	join_domain_force.vbs domain username password OU'The last parameter is optional'Example:'join_domain_force.vbs KACE administrator pw "OU=WorkStations,OU=MyOU,DC=kace,DC=local"Const JOIN_DOMAIN             = 1Const ACCT_CREATE             = 2Const ACCT_DELETE             = 4Const WIN9X_UPGRADE           = 16Const DOMAIN_JOIN_IF_JOINED   = 32Const JOIN_UNSECURE           = 64Const MACHINE_PASSWORD_PASSED = 128Const DEFERRED_SPN_SET        = 256Const INSTALL_INVOCATION      = 262144If WScript.Arguments.Count < 3 or WScript.Arguments.Count > 4 Then	' If the number of arguments is not correct terminates the script	WScript.Quit(1)End IfstrDomain   = WScript.Arguments.Item(0)strUser = WScript.Arguments.Item(1)strPassword = WScript.Arguments.Item(2)'set the OU if provided as parameterSet objNetwork = CreateObject("WScript.Network")strComputer = objNetwork.ComputerNameSet objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _                             strComputer & _                             "\root\cimv2:Win32_ComputerSystem.Name='" _                             & strComputer & "'")If WScript.Arguments.Count = 4 Then	ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _		      strPassword, _		      strDomain & "\" & strUser, _		      WScript.Arguments.Item(3), _		      DOMAIN_JOIN_IF_JOINED+JOIN_DOMAIN+ACCT_CREATE)Else							 	ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _                        strPassword, _                        strDomain & "\" & strUser, _													                        NULL, _	                DOMAIN_JOIN_IF_JOINED+JOIN_DOMAIN+ACCT_CREATE)											End IfWScript.Quit(ReturnValue)
12GUAV.png

Kind regards,
 Marco - StockTrader
Answered 12/04/2015 by: StockTrader
Red Belt

 
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