What I am trying to do is the following: List all computers that are a member of either a certain group or a certain OU (whichever is easier to code). I want to "write" that list to memory, then I want the server to ping every computer in that list in memory and if the computer responds, then I want to shut the computer down.

I have managed to adapt existing code to ping a computer and if online, then shut the computer down

 Quote:

;=============
; Ping computer
;=============

Function OSPing($sComputer)
Shell '"'+%COMSPEC%+'" /c ping -n 1 '+$sComputer+' |find /C "TTL=" >nul'
$OSPing = NOT @ERROR
If $OSPing = 1
$ShellCMD = 'shutdown -s -f -m ' + $sComputer + ' -t 300'
Shell $ShellCMD
Else
? "computer is not on the network"
Endif
EndFunction

What I will obviously need to do is make $sComputer read from the list in memory and loop for each computer in that list. That I am sure that I can work out. However I have spent hours online trying to adapt existing code to list all computers that are a member of either an OU or group, but I have failed to get anything to work.

The closest that I have come is using this UDF

 Quote:

;================================================================================================
; Checks which security group the computer belongs to
;================================================================================================

Function ComputerInGroup($group,optional $Domain)

Dim $oGrp
if not $domain $domain=@domain endif
$oGrp = GetObject("WinNT://" + $domain + "/" + $group + ",group" )
if @error exit 1 endif

if $oGrp.IsMember("WinNT://" + $domain + "/" + @wksta + "$$" )
$ComputerInGroup=1
else
$ComputerInGroup=0
endif
EndFunction

What I have done is tried to modify the above UDF to output the list of computers to memory, instead of checking whether this computer is a member of specified group.

so I did this:

 Quote:

;================================================================================================
; Obtain list of computers in global group
;
;===============================================================================================

Function groupmembers($group,optional $Domain)

Dim $oGrp
if not $domain $domain=@domain endif
$oGrp = GetObject("WinNT://" + $domain + "/" + $group + ",group" )
if @error exit 1 endif

for each $x in $oGrp.Ismember
? $X
; OSPing($sComputer) (remmed out for the moment, as should not be here)
loop
EndFunction

I am aware that you cannot use a function within a function, so I should not be using Osping($sComputer) in the function groupmembers. I am just displaying it here to illustrate how the logic of my udf is supposed to work. My problem is that my modified script for obtaining list of computers in global group does not seem to do anything. $x shows nothing and the script does not seem to do anything. I am sure its because I don't understand how to code this properly. The problem seems to be that I can find any number of examples of checking if user or computer is a member of something, but I cannot find anything to list all computers that are a member of a group/OU. I found something with users, but I couldn't get it to work for computers. what am I doing wrong? Thanks