/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


Wsname question, KACE?

06/10/2014 3691 views

Hi!

I have a question about wsname. I have a almost working batch script with wsname, script rename the computer. The problem is if the computer name already is in the AD, the script/wsname not working. It said something about the account is already exists. But if I delete computer name in AD before installation is working fine. Is there a SIMPLE solution to fix this, maybe a commando or something?

Many thx, Janne.

 

0 Comments   [ + ] Show comments

Comments


All Answers

0

If the machine is already in the domain and the new name is already in the domain this will occur.  Do not precreate the new name when renaming a machine already in the domain.  the only other thing is to create a script that remove the machine, rename the machine and rejoin it to the domain.  Since you are using the k2000 you want to rename the machine before you join it

This is a script to rename a machine in the domain to a existing name in the domain

start /wait Wmic computersystem where name="%computername%" call unjoindomainorworkgroup

start /wait wmic.exe  computersystem where "caption='%computername%'" rename newname

wmic.exe  computersystem where "caption='loanerssd7x64'" rename ssdloaner7x64 - See more at: http://www.itninja.com/question/wmic-kbox-script#sthash.Hqfiixe7.dpuf

start /wait cscript.exe -b c:\windows\w2d\join_domain.vbs tmccacad.tmcc.edu domainuser password domainserverIP

shutdown -r -t 1

 

join_domain.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)



Answered 06/10/2014 by: SMal.tmcc
Red Belt

0

Hi and thx for the script! Problem is I want a specific computer name. I want to use the serial number from the computer, like this : DT-83ur4jkj or LT-03ir0if. Thats why I use wsname.

Answered 06/10/2014 by: Swede
Blue Belt

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