Page 1 of 1 1
Topic Options
#211261 - 2016-04-04 09:51 PM List domain computers
Iz3k34l Offline
Just in Town

Registered: 2016-02-19
Posts: 4
Loc: Texas
is there a way to query the domain for a list of domain computers?
Ultimately i want to rename a computer and join it to a domain.
I want to be able to step through computer names pc1, pc2 by verifying the computer is not already on the domain or the computer name inst already being used, then naming the next sequential number.


Thanks

Top
#211262 - 2016-04-05 02:13 AM Re: List domain computers [Re: Iz3k34l]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Welcome to KORG!!

I had to search the archives folder for this, but it's simple and effective:
 Code:
Break on

; Array of domains to query
$aDomains = "@DOMAIN", ''


For Each $Domain in $aDomains
 If $Domain
   "Processing " + $Domain ?

  $aList = GetMachineList($Domain)

  1 + Ubound($aList) " records found." ?
  For Each $Target in $aList
    $Target ?
  Next
 EndIf
Next




Function GetMachineList($DomainName)
	
  Dim $Machines[0], $iX
	
	
  ;Create domain object
  $Domain = GetObject("WinNT://" + $DomainName + ",domain")
	
  ;Set container object equal to domain object.
  $Container = $Domain
	
  ;Iterates through EVERY object in the domain.  Those
  ;objects that match the class are included in the array.
  $iX = -1
  For Each $Computer In $Container
	  
    If $Computer.Class = "Computer"
      $iX = $iX + 1
      ReDim Preserve $Machines[$iX]
      $Machines[$iX] = $Computer.Name
    EndIf
	  
  Next	

  ; Return the $Machines array...
  $GetMachineList = $Machines
	
  ;Object cleanup
  $Domain = 0
  $Container = 0
	
EndFunction
Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#211263 - 2016-04-05 02:15 AM Re: List domain computers [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Look at the AScan() function - once the above code returns the list of computer names, you can use AScan() to search for the new name. If the returned value is -1, it doesn't exist in the array, any other value represents it's index in the array.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#211272 - 2016-04-07 06:18 PM Re: List domain computers [Re: Glenn Barnas]
Iz3k34l Offline
Just in Town

Registered: 2016-02-19
Posts: 4
Loc: Texas
ok, thanks so much.. i got it to compare and to read in a CSV list, strip out the comma, and compare but now i want to limit the return of the first -1 it finds because as it stand it return the last...
 Code:
For Each $Target in $aData[0]
   if (ASCAN($aList,$Target,,,1) < 0)   
   ? $Target ?
   $rTurn = $Target
   
   EndIF
   ;? $Target
Next

? $rTurn



Thanks

Top
#211285 - 2016-04-08 11:06 PM Re: List domain computers [Re: Iz3k34l]
Iz3k34l Offline
Just in Town

Registered: 2016-02-19
Posts: 4
Loc: Texas
Ok so on to another note, i need to be able to search the domain for a list of computers already on the domain BEFORE being joined to the domain ;o)... i got the script to search for systems within the domain, return a value (not exactly the way i wanted but for testing it will do) and rename the system with the returned value... after a reboot it gave me a domain trust error... any ideas on how to get the computer list from the domain BEFORE being added to the domain?

Thanks

Top
#211286 - 2016-04-09 04:18 AM Re: List domain computers [Re: Iz3k34l]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
 Code:
GetObject("WinNT:").OpenDSObject("WinNT://MYDOMAIN",altUser, altPwd, 1)
_________________________
!

download KiXnet

Top
#211288 - 2016-04-10 02:33 AM Re: List domain computers [Re: Lonkero]
Iz3k34l Offline
Just in Town

Registered: 2016-02-19
Posts: 4
Loc: Texas
Thanks Glenn and Lonkero; here is the updated code that will get a list of domain computers without being on a domain computer

 Code:
Function GetMachineList($DomainName, $DomainUser, $DomianPass)
	
  Dim $Machines[0], $iX
	
	
  ;Create domain object
  $Domain = GetObject("WinNT:").OpenDSObject("WinNT://$DomainName" , $DomainUser, $DomainPass, 1)
	
  ;Set container object equal to domain object.
  $Container = $Domain
	
  ;Iterates through EVERY object in the domain.  Those
  ;objects that match the class are included in the array.
  $iX = -1
  For Each $Computer In $Container
	  
    If $Computer.Class = "Computer"
      $iX = $iX + 1
      ReDim Preserve $Machines[$iX]
      $Machines[$iX] = $Computer.Name
    EndIf
	  
  Next	

  ; Return the $Machines array...
  $GetMachineList = $Machines
	
  ;Object cleanup
  $Domain = 0
  $Container = 0
	
EndFunction


Edited by Iz3k34l (2016-04-10 02:34 AM)

Top
#211291 - 2016-04-10 05:19 PM Re: List domain computers [Re: Iz3k34l]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Great! And we especially appreciate following up with your code - I'm sure it will help others!

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.061 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org