/bundles/itninjaweb/img/Breadcrumb_cap_w.png
Any suggestions as to why the below doesn't work?

Dim objDC, strDomain, strComputer
strDomain = "domain"
strComputer = "machine"

Sub RemoveComputer
On error resume next
Set objDC = getobject("WinNT://" & strDomain )
objDC.Delete "Computer", strComputer
if err = 0 Then
wscript.echo "RemoveComputer = true"
else
wscript.echo "RemoveComputer = false"
end if
On error goto 0
End Sub
0 Comments   [ - ] Hide Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity

Answers

0
Hell Naffcat,

Its because you have included the major script in a sub-routine, but you aren't actually calling it.
Answered 04/05/2005 by: brenthunter2005
Fifth Degree Brown Belt

Please log in to comment
0
Many thanks Brent - it had been a long day!
Answered 04/05/2005 by: Naffcat
Senior Purple Belt

Please log in to comment
0
I really like those easy problems, especially when they only take two seconds out of your day. [:D]
Answered 04/06/2005 by: brenthunter2005
Fifth Degree Brown Belt

Please log in to comment
0
Gack!

You WMI guys :)

I would have looked up the API call to unjoin my machine from the domain and used Call Dll Function to accomplish it... I would have JOINED the machine to a workgroup...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/netmgmt/netjoindomain.asp

The NetJoinDomain function joins a computer to a workgroup or domain.

NET_API_STATUS NetJoinDomain(
LPCWSTR lpServer,
LPCWSTR lpDomain,
LPCWSTR lpAccountOU,
LPCWSTR lpAccount,
LPCWSTR lpPassword,
DWORD fJoinOptions
);
Answered 04/22/2005 by: sean_c_roberts
Senior Purple Belt

Please log in to comment
0
I have just started to get into scripting and everyone seems to assume that you know how to get a script to execute.
I can put code into a txt file till the cows come home but how do I actually get it to execute?!?!?!

Anyone know any good books that dont assume these things? I am a do'er once I have done something I can just build off of that but I cannot read a book and just figure out that this is what you do to get everything going.

NET_API_STATUS NetJoinDomain(
LPCWSTR lpServer,
LPCWSTR lpDomain,
LPCWSTR lpAccountOU,
LPCWSTR lpAccount,
LPCWSTR lpPassword,
DWORD fJoinOptions
);

Jason
Answered 05/16/2005 by: jwarner777
Senior Yellow Belt

Please log in to comment
0
Does anybody know of a tool or script that can remove around 3000 old computer accounts from our NT (non AD) domain?

Thanks in advance

Gary
Answered 06/30/2005 by: glwday
Orange Belt

Please log in to comment
0
Do you know the names of the computers? ie: are they in a spreadsheet etc?
Answered 06/30/2005 by: brenthunter2005
Fifth Degree Brown Belt

Please log in to comment
0
Yes I have them in a txt file (I did a NETDOM member to get a list of all accounts and then compared it against a list from our logs directory - each login on a pc gets a txt file created on a server so we can see last login date, user, password age etc).
Answered 07/01/2005 by: glwday
Orange Belt

Please log in to comment
0
OK, first of all your script needs to read the contents of this text file/spreadsheet into an array and then delete the computer account from the domain. Something like this would suffice if the text file were simple:

Text file called 'computers.txt':
computer01
computer03
computer05
server04
computer09
computer10


Script:
strTextFile = "C:\temp\computers.txt"
strDomain = "DOMAINNAME"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDC = GetObject("WinNT://" & strDomain )

Set objFile = objFSO.OpenTextFile(strTextFile,1)
Do Until objFile.AtEndOfTextStream <> TRUE
strLine = objFile.ReadLine
objDC.Delete "Computer", strLine
Loop

objFile.Close
Set objFSO = Nothing
Set objDC = Nothing

wscript.echo "Completed"
Answered 07/04/2005 by: brenthunter2005
Fifth Degree Brown Belt

Please log in to comment
0
On Error Resume Next
WScript.Echo "Start"
LOcal_Admin_Acct = "administrator"
LOcal_Admin_PW = "password1"
Workgroup_To_Join = "workgroup"
Path = "C:\"

Set E_Log = CreateObject("Scripting.FileSystemObject").OpenTextFile(Path & "Log.txt", 8, True)
DeviceList = CreateObject("Scripting.FileSystemObject").OpenTextFile(Path & "WS.txt").ReadAll

Set wshshell = CreateObject("wscript.shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")



For Each DeviceName in split(DeviceList,vbcrlf)
Wshshell.run "cmd /c C:\netdom.exe /u:" & DeviceName & "\" & LOcal_Admin_Acct & " /p:" & LOcal_Admin_PW & " MEMBER \\" & DeviceName & " /JOINWORKGROUP " & Workgroup_To_Join & " >> C:\netdom.txt", 0, True
Get_Results Devicename
Next

wscript.echo "Done"

Set WshNetwork = Nothing
Set Wshshell = Nothing



'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Sub Get_Results(DeviceName)
Result = CreateObject("Scripting.FileSystemObject").OpenTextFile("c:\netdom.txt").ReadAll
For Each Line_Result in split(Result,vbcrlf)
If instr(Line_Result,"successfully") > 0 then
E_Log.writeline Devicename & vbtab & Line_Result & vbtab & Now() & VbCrLf
End If
Next
End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Function Get_USerID
NT_ID = InputBox("Enter Domain Admin Acct. required to join Domain: ", "Get Valid UserID")
If NT_ID = "" Then
Msgbox "You did not enter anything for USerID...... Terminating Script!", 16, "No Account Entered"
wscript.quit
Else
Get_USerID = NT_ID
End If
End Function

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Function Get_Password
Password = InputBox("Enter Password:", "Enter Password")
If Password = "" then
Msgbox "You did not enter anything for Password...... Terminating Script!", 16 , "No Password Entered"
wscript.quit
Else
Get_Password = Password
End If
End Function






LOcal_Admin_Acct = this is the local administrator account for the pc (most likely Administrator )
LOcal_Admin_PW = This is the local admin passowrd ( ????)
Workgroup_To_Join = this is the workgroup name you would like your PC's to join
netdom should be placed under the c drive also you should place it in system32
Path = Here is where you will have to place you list of workstaion in a text file under the c drive ( C:\ws.txt)
In the ws.txt the pcs shoud have no spaces in their name. eg
computer1
computer2
computer3
computer4
computer5
computer6

etc


* Not all versions of NETDOM works the same.

Enjoy
Answered 07/11/2005 by: UcMerrill
Senior Yellow Belt

Please log in to comment
0
I found this straight forward line to remove a computer works

NETDOM /Domain:Domain01 MEMBER BS0681618 /DELETE

From there it was easy to use the concatenate function in excel. First create three columns
Column A Column B Column C
NETDOM /Domain:Domain01 MEMBER - accountto remove - /DELETE

Concatenate lets you join the values in different cells. In Col D enter
=CONCATENATE(A1,B1,C1) and you get
NETDOM /Domain:Domain01 MEMBER accounttoremove /DELETE

Then copy the formula down for the number of assets you have in column B. then I copy and paste the joined up entries into a batch file, and job done ready to run.

This is on a Windows 2000 without AD.
Answered 07/20/2005 by: glwday
Orange Belt

Please log in to comment