/build/static/layout/Breadcrumb_cap_w.png

Addition to existing script (set pc name to ASSETTAG and join domain)

Hi there,

I'm working on a Kace k2100 appliance and thing are going quite well.
On the appdeloy website i found this set op scripts that are changing the pc name with wsname and than join the pc to a certain domain.
This script workes great, especially the pc renaming part come in very handy for our company.

I would like to change the script a bit, so that the pc/laptop automatically is added to a certain OU. The name of the OU will be hardcoded in the script.

I,ve seen already some (a lot :-) ) of scripts passing by, also on this forum, but none of them extracts a computername from BIOS, like assettag or servicetag.

I,ve tried to modify the script by myself, but still with no results. Changing the computername goes well, but the adding to Domain/Organizational Unit part does not work.
The scripts, and the changes i've made to the are below. Can anyone please check them and give me some advice ?

Script 1


@echo Rename and Join a Windows 7 x64 computer to a domain

xcopy /S /E /I source c:\source
c:\source\1_wsname_x64.bat


Script 2


echo Changing the name of the Windows 7 x64 computer

c:\source\wsname.exe /N:$ASSETTAG /Logfile:C:\wsname.txt

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v V1 /t REG_SZ /d "CMD /C \"C:\source\2_JoinDomain_x64.bat\"" /f

shutdown -r -t 45


Script 3

REM Join a Windows 7 x64 computer to the domain

REM ***** Join_Domain.vbs <domain> <DomainUser> <password> <Default domain DNS Server IP> *****>

REM ==========================================================
REM Here I added the OU=test,dc=domain,dc=local part.
REM ===========================================================

C:\source\Join_Domain.vbs domain.local admin Password 172.16.0.15 OU=test,dc=domain,dc=local

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 0 /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d <NULL> /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d <NULL> /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v V1 /t REG_SZ /d "CMD /C \"rd /s /q C:\source\""

shutdown -r -t 45


Script 4


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

'=======================================================
'Here i changed the digit: WScript.Arguments.Count > 4 to WScript.Arguments.Count > 5
'=======================================================

If WScript.Arguments.Count < 3 or WScript.Arguments.Count > 5 Then
WScript.Quit
'=======================================================
' Here i added the strOU item
'=======================================================
Else
strDomain = WScript.Arguments.Item(0)
strUser = WScript.Arguments.Item(1)
strPassword = WScript.Arguments.Item(2)
strOU = WScript.Arguments.Item(4)

'=======================================================
'Here i changed: WScript.Arguments.Count = 4 to WScript.Arguments.Count = 5
'=======================================================
'set DNS IP address
If WScript.Arguments.Count = 5 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

'==========================================================
'I changed: strDomain & "\" & strUser, _
' NULL, _
' JOIN_DOMAIN+ACCT_CREATE)
'
'into: strDomain & "\" & strUser, _
' strOU, _
' JOIN_DOMAIN+ACCT_CREATE)
'============================================================


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


Thanks in advance,
Mesjoggah

0 Comments   [ + ] Show comments

Answers (1)

Posted by: Mesjoggah 12 years ago
Orange Belt
0
Nevermind. The script workes. Just made a typo in domain credentials.... sigh...[:@]
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
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