Get the IP and choose between which domain, using the ip address.
I am trying to have one image for 4 different companies, each company has a different domain, I want to have a K2000 image that will get the ip address and add it to the correct domain(using the ip address), without user input. If there is anything out there please let me know. If you guys have better ideas let me know.
0 Comments
[ + ] Show comments
Answers (4)
Answer Summary:
Please log in to answer
Posted by:
aragorn.2003
9 years ago
I think this is related to your script to join the domain.
You can determine a IP address via VisualBasic Script
dim NIC1, Nic, StrIP
Set NIC1 = GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
For Each Nic in NIC1
if Nic.IPEnabled then
StrIP = Nic.IPAddress(i)
MsgBox StrIP
Wscript.quit
end if
next
or you can do this via cmd
@echo off
for /f "delims=[] tokens=2" %%a in ('ping %computername% -n 1 -4 ^| findstr "["') do (set thisip=%%a)
echo %thisip%
and now create a if condition to join different domains based on the IP
Comments:
-
This is what I have right now, but it keeps coming up with an error.
Cscript Join_Domain.vbs username password
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'pulls IP address and trims the first 3 octets
Set colAdapters = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=True")
For Each objAdapter in colAdapters
For Each strAddress in objAdapter.IPAddress
arrOctets = Split(strAddress, ".")
If arrOctets(0) <> "" Then
strSubnet = arrOctets(0) & "." & arrOctets(1) & "." & arrOctets(2)
x = 1
Exit For
End If
If x = 1 Then
Exit For
End If
Next
Next
Select Case strSubnet
Case "10.70.240"
strDomain = "cfpfire.com"
Case "10.60.240"
strDomain = "DomainB"
End Select
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
' Duff arguments so return non zero so the task is marked as failed.
WScript.Quit(1)
Else
strUser = WScript.Arguments.Item(0)
strPassword = WScript.Arguments.Item(1)
'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)
WScript.Quit(ReturnValue) - Jstump 9 years ago-
And what is the error message and error number? - aragorn.2003 9 years ago
-
Task ID: 75
Task name: Jon Test Add to Domain
Return code: 2
Error description: The system cannot find the file specified. - Jstump 9 years ago
-
Where do you set the variable strComputer in the first line. try it with localhost and this error is fixed. Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") - aragorn.2003 9 years ago
-
I tried running it with "Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")" but came up with the same error. - Jstump 9 years ago
-
OK, Task ID 75 and the error description is not an error within the vbs document but within the KACE configuration. Did you upload the .vbs file to the Post-installation Task. Another way is to change the error handling within the scripted installation to "Prompt on errors". The scripted installation will then stop the deployment at this position and provides you with the possibility to debug this error, e.g. by opening a command console. - aragorn.2003 9 years ago
-
The vbs is uploaded and the script i use in the command line is "Cscript New_Text.vbs username password" the uploaded vbs script is called New_Text.vbs and the run-time environment is windows. Everything is the same as the working join_domain.vbs except for the parts where I changed how the strDomain is found (via ip). - Jstump 9 years ago
Posted by:
aragorn.2003
9 years ago
Posted by:
Jstump
9 years ago