Jump to content

Can't get sysprep to delete a computer account


Recommended Posts

I'm using the following code to remove a computer account from a domain:

Dim strSerialNumber
strSerialNumber="PC1234"
Set objCont = GetObject("WinNT://" & "domain.com")
objCont.Delete "Computer", strSerialNumber

and can't get it to work. However, this does work:

Set objCont = GetObject("WinNT://" & "domain.com")
objCont.Delete "Computer", "PC1234"

What gives?

Background and extra credit question for cash: PCs here get reimaged many times, but keep the same computer name. So I'm trying to get sysprep to pull the Dell Asset tag and use that to join the domain. I got all that working, but the joining of the domain fails if the computer account is already there, so I'm using the above script to try and delete it. Sadly, this is taking me 3+ VBScripts to complete this task, because I suck. If you have any ideas how to make this all one script, I will love you forever and paypal you some cash. Thanks.

Edited by fly
Link to comment
Share on other sites

  • 2 weeks later...

Hello Fly!

First of all: leave imaging and begin with scripting solutions (unattended). It will save you lot of time + problems

To your problem:

This is what I found in my DB

Dim strDomain : strDomain = "domain.com"
Dim strComputer

strComputer = InputBox( "Please the name of the computer to be removed from the domain", "Input" )
RemoveComputer strDomain, strComputer

Sub RemoveComputer( strDomain, strComputer )
   Dim objDC
   Set objDC = getobject("WinNT://" & strDomain )
   objDC.Delete( "Computer", strComputer )
End Sub

However you should use ONE script, that will check if there is computer account and it will call function funcRemoveComputer...

Please send me PM next week, I will write it for you

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...