This is a part of my script. I'm trying to retrieve disk space from my servers:

$myarray = 1, 2
For Each $element In $myarray


$Info = wmiquery ("Name","Win32_LogicalDisk", "cwtwaw05") [$element]

$element = $element - 1


$Total = wmiquery ("Size","Win32_LogicalDisk", "cwtwaw05") [$element]

$Free = wmiquery ("FreeSpace","Win32_LogicalDisk", "cwtwaw05") [$element]



$diskinformation = "CWTWAW05 :" + $Info + " "+$Total+" "+ $Free + @crlf
$servinformation = $servinformation + $diskinformation

Next

I'm using the following function:

Function WMIQuery($sWhat, $sFrom, Optional $sComputer, Optional $sWhere, Optional $x)

Dim $sQuery, $objEnum, $sValue, $sItem, $lUbound
Dim $aTMP[0]
$sQuery = "Select " + $sWhat + " From "+ $sFrom
If NOT $sComputer $sComputer=@WKSTA EndIf
If $sWhere AND $x $sQuery = $sQuery + " Where " + $sWhere + " = '"+$x+"'" EndIf
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//"+$sComputer) If

@ERROR Exit Val("&"+Right(DecToHex(@ERROR),4)) Return EndIf
$objEnum = $SystemSet.ExecQuery($sQuery)
If @ERROR Exit Val("&"+Right(DecToHex(@ERROR),4)) Return
EndIf
For Each $objInstance In $objEnum
If $objInstance
$=Execute("$$sValue = $$objInstance.$sWhat")
Select
Case VarType($sValue) & 8192
For Each $sItem In $sValue
$lUbound = Ubound($aTMP)
If $aTMP[$lUbound] >' '

$lUbound = $lUbound +1
ReDim Preserve $aTMP[$lUbound]
EndIf
$aTMP[$lUbound] = Trim($sItem)
Next
Case 1
$lUbound = Ubound($aTMP)
If $aTMP[$lUbound] >' ' $lUbound = $lUbound +1
ReDim Preserve $aTMP[$lUbound]
EndIf $aTMP[$lUbound] = Trim($sValue)
EndSelect EndIf
Next
$WMIQuery = $aTMP
Exit Val("&"+Right(DecToHex(@ERROR),4))

EndFunction