I am trying to enum all computers in a domain so that I can move them to another domain. The code that I am using is from the ComNetView UDF. For some reason it keeps returning users instead of computers.
Below is the code that I am using. Any help is appreciated.
Code:
Break On
$System = CreateObject("Kixtart.System")
;KD START
;************* Form **************
$Form = $System.Form()
$Form.BackColor = 212,208,200
$Form.Height = 147
$Form.Text = "Domain Move"
$Form.Width = 223
;**************************************
;************* TextBox1 **************
$TextBox1 = $Form.Controls.TextBox()
$TextBox1.Height = 20
$TextBox1.Left = 105
$TextBox1.Text = ""
$TextBox1.Top = 0
$TextBox1.Width = 100
;**************************************
;************* TextBox2 **************
$TextBox2 = $Form.Controls.TextBox()
$TextBox2.Height = 20
$TextBox2.Left = 105
$TextBox2.PasswordChar = "*"
$TextBox2.Text = ""
$TextBox2.Top = 30
$TextBox2.Width = 100
;**************************************
;************* TextBox3 **************
$TextBox3 = $Form.Controls.TextBox()
$TextBox3.Height = 20
$TextBox3.Left = 105
$TextBox3.Text = ""
$TextBox3.Top = 30
$TextBox3.Width = 100
$TextBox3.Visible = False
;**************************************
;************* Label1 **************
$Label1 = $Form.Controls.Label()
$Label1.BackColor = 212,208,200
$Label1.Height = 23
$Label1.Left = 0
$Label1.Text = "UserName"
$Label1.Top = 0
$Label1.Width = 100
;**************************************
;************* Label2 **************
$Label2 = $Form.Controls.Label()
$Label2.BackColor = 212,208,200
$Label2.Height = 23
$Label2.Left = 0
$Label2.Text = "Password"
$Label2.Top = 30
$Label2.Width = 100
;**************************************
;************* Label3 **************
$Label3 = $Form.Controls.Label()
$Label3.BackColor = 212,208,200
$Label3.Height = 23
$Label3.Left = 0
$Label3.Text = "Domain"
$Label3.Top = 60
$Label3.Width = 100
;************ Label4 ******************
$Label4 = $Form.Controls.Label()
$Label4.BackColor = 212,208,200
$Label4.Height = 23
$Label4.Left = 0
$Label4.Top = 30
$Label4.Width = 100
$Label4.Visible = False
;**************************************
;************* Button1 **************
$Button1 = $Form.Controls.Button()
$Button1.Height = 23
$Button1.Left = 0
$Button1.Text = "Start"
$Button1.Top = 90
$Button1.Width = 75
$Button1.OnClick = "DoIt ()"
;**************************************
;************* Button2 **************
$Button2 = $Form.Controls.Button()
$Button2.Height = 23
$Button2.Left = 120
$Button2.Text = "Exit"
$Button2.Top = 90
$Button2.Width = 75
$Button2.OnClick = "Quit"
;**************************************
;************* Button3 **************
$Button3 = $Form.Controls.Button()
$Button3.Height = 23
$Button3.Left = 0
$Button3.Text = "Convert"
$Button3.Top = 90
$Button3.Width = 75
$Button3.OnClick = "Moving ($List, $User, $Pass)"
$Button3.Visible = False
$Button3.Enabled = False
;**************************************
;************* ComboBox1 **************
$ComboBox1 = $Form.Controls.ComboBox()
$ComboBox1.DropDownWidth = 121
$ComboBox1.Height = 21
$ComboBox1.Left = 105
$ComboBox1.Sorted = "False"
$ComboBox1.List = "HSSANCFY", "HSSJNUFY", "HSSFAIFY"
$ComboBox1.ListIndex = 0
$ComboBox1.Top = 60
$ComboBox1.Width = 100
;**************************************
;KD END
$Form.Show
While $Form.Visible
$=Execute($Form.DoEvents())
Loop
Exit 1
Global $list, $objDomain, $objComputername, $filter[0], $ComNetView
Global $User, $Pass
SetOption("NoVarsInStings", "On")
Function DoIt ()
;**************************************
; Validation logic
;**************************************
If $TextBox1.Text = ""
$nul= MessageBox ("You must enter all information before continuing", "OOPS")
Exit
Else $User = $TextBox1.Text
EndIf
If $TextBox2.Text = ""
$nul= MessageBox ("You must enter all information before continuing", "OOPS")
Exit
Else $Pass = $TextBox2.Text
EndIf
;**************************************
; Turn off extra information not needed
;**************************************
$label1.visible = False
$Textbox1.visible = False
$label2.visible = False
$Textbox2.visible = False
$label3.visible = False
$ComboBox1.visible = False
$Button1.Visible = False
$Button1.Enabled = False
$Button3.Visible = True
$Domain = $combobox1.text
;**************************************
; Begin getting list of workstations
;**************************************
Debug On
$Label4.Text = "Working"
$Label4.visible = True
;**************************************
; Taken from Sealeopards UDF ComNetView
;**************************************
if val(@INWIN)<>1 or val(@DOS)<5
exit 196
endif
$domain = trim($domain)
if $domain=''
$domain=@DOMAIN
endif
$filter[0]='Computer'
$objDomain = GetObject('WinNT://' + $domain + ',domain')
if @ERROR
exit @ERROR
endif
$objDomain.Filter=$filter
if @ERROR
exit @ERROR
endif
For Each $objComputername In $objDomain
redim preserve $list[ubound($list)+1]
$list[ubound($list)] = $objComputername.Name
Next
$objDomain = 0
;**************************************
; should have an array now, but don't
;**************************************
;**************************************
; Change labels and set up for site entry
;**************************************
$label4.text = " Enter Site Code"
$TextBox3.visible = True
$TextBox3.SetFocus
$Button3.Enabled = True
EndFunction
Function Moving ($List, $User, $Pass)
;**************************************
; Check to see if Site ID is long enough
;**************************************
If Len ($textbox3.text) <> 3
$nul= MessageBox ("You must enter all information before continuing", "OOPS")
Exit
Else
$site = $textbox3.text
EndIf
;**************************************
; Now we look for a match and move the
; computer from one domain to another
;**************************************
For each $Computer in $List
if Left($Computer, 3) = $site
; Run "CMD NETDOM MOVE " +$Computer +"DOMAIN:HSSOCS USERD:"+$User+" PASSWORDD:"+$Pass
; Write completion results to a file
endif
Next
EndFunction