Break On
Dim $SO,$Server,$Servers,$ValidSystem,$Share,$Item,$HS,$x,$File,$Report,$sComputer,$Send,$Results,$Results1,$Results2
Dim $Results3,$NB,$Arp,$Status
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$Servers=ReadFile(@ScriptDir+'\servers.txt')
$File = @ScriptDir+'\ServerDiskSpace.txt'
$Report = RedirectOutput($File,1)
For Each $sComputer In $Servers
If $sComputer
$Send=0
$Results=Join(wshpipe('ping '+$sComputer+' -n 1',1),@CRLF)
If UBound(Split($sComputer,'.'))=3 ;IP was supplied from list
$NB='IP'
$Arp=0
$Results1=Trim(Split(Split(Split($Results,":")[4],"Received = ")[1],", Lost")[0])
Else ; NetBIOS name was supplied from list
$NB='NetBIOS'
$Arp=1
$Results1=Trim(Split(Split(Split($Results,":")[4],"Received = ")[1],", Lost")[0])
$Results2=Trim(Split(Split($Results,"[")[1],"]")[0])
$Results3=Trim(Split(Split($Results,"could")[1],"find")[0])
EndIf
If $Arp ; NetBIOS name was supplied from list
Select
Case $Results3
$Status=$sComputer+' using '+$NB+' is not in WINS-DNS'
? $Status
$Send=0
Case $Results2
If
$Results1 >0 $Status=$sComputer+' using '+$NB+' '+$Results2+' is responding to ping'
$Send=1
Else
$Status=$sComputer+' using '+$NB+' has WINS-DNS entry but is not responding.'
? $Status
$Send=0
EndIf
Case 1
$Status=$sComputer+' generated an unknown error '+ 'ERR: '+@ERROR
? $Status
$Send=0
EndSelect
Else ;IP was supplied from list
If $Results1 >0
$Status=$sComputer+' using '+$NB+' is responding to ping'
$Send=1
Else
$Status=$sComputer+' using '+$NB+' is NOT responding to ping'
? $Status
$Send=0
EndIf
EndIf
If $Send
If ConfirmWMI($sComputer)
$HS=ListHiddenShares($sComputer)
$HS=QS(Split(Join(Split($HS,CHR(42)),CHR(32)),CHR(47))) ;Sort the list using QS UDF
For $x=0 To UBound($HS)
If $x
? $sComputer + CHR(32) + $HS[$x]
EndIf
Next
EndIf
EndIf
EndIf
Next
$Report = RedirectOutput("")
Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
Dim $oExec, $Output
$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
If Not VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
If Not $NoEcho $Output Endif
$WshPipe=Split(Join(Split($Output,CHR(13)),CHR(32)),CHR(10))
Exit($oExec.ExitCode)
EndFunction
Function ListHiddenShares($sComputer)
Dim $objWMIService,$colShares,$objShare,$HiddenShare
If Not $sComputer $sComputer = @WKSTA EndIf
$sComputer = '\\' + $sComputer + '\'
$objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!" + $sComputer + "root\cimv2")
$colShares = $objWMIService.ExecQuery("Select * from Win32_Share")
For each $objShare In $colShares
If $objShare.Type = '-2147483648' And Not InStr($objShare.Name,'ADMIN$')
$HiddenShare = $HiddenShare + $objShare.Name + CHR(42) + Diskspace($sComputer+ $objShare.Name) + CHR(47)
EndIf
Next
$ListHiddenShares = $HiddenShare
EndFunction
Function Diskspace(optional $drive, optional $format)
Dim $objWMIService, $sWQL, $colDrives, $objDrive
If Not $drive
$drive='%WINDIR%'
EndIf
$format=Val($format)
If $format<5
$format=IIf($format=1,1024,IIf($format=2,1024.0*1024,IIf($format=3,1024.0*1024*1024,IIf($format=4,1024.0*1024*1024*1024,1))))
$diskspace=CDBL(GetDiskSpace($drive))/$format
Else
$objWMIService=GetObject('winmgmts:{impersonationLevel=impersonate}!\\'+@WKSTA+'\root\cimv2')
$sWQL = "SELECT Size, FreeSpace FROM Win32_LogicalDisk WHERE Name='"+Left($drive,2)+"'"
$colDrives=$objWMIService.ExecQuery($sWQL)
For Each $objDrive in $colDrives
$diskspace=CDBL($objDrive.FreeSpace)/CDBL($objDrive.Size)*100
Next
EndIf
Exit @ERROR
EndFunction
Function ConfirmWMI(Optional $sComputer)
Dim $Computer,$Namespace,$WinDir,$Target,$WMIVer,$objWMIService,$WinDrive
If Not $sComputer $sComputer = @WKSTA EndIf
$sComputer = '\\' + $sComputer + '\'
$WinDir = $sComputer+Join(Split(ReadValue($sComputer+ 'HKLM\Software\Microsoft\Windows NT\CurrentVersion', 'SystemRoot'),':'),Chr(36))
If @ERROR
Exit @ERROR
EndIf
$Target = $WinDir + '\system32\wbem\wbemdisp.dll'
If Exist($Target)
$WMIVer = Trim(GetFileVersion($Target,'BinFileVersion'))
If @ERROR
Exit @ERROR
EndIf
Else
Exit 2
EndIf
$ConfirmWMI=$WMIVer
$Namespace = "root\cimv2"
If $WMIVer
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!" + $sComputer + $Namespace)
If @ERROR
Exit Val("&"+Right(DecToHex(@ERROR),4))
Else
Exit 0
EndIf
EndIf
Exit 2
EndFunction
Function ReadFile($file)
Dim $lf, $f, $_, $t
$lf=Chr(10)
$f=FreeFileHandle
$_=Open($f,$file)
If @ERROR Exit @ERROR EndIf
Do $t=$t+$lf+ReadLine($f) Until @ERROR
$_=Close($f)
$ReadFile=Split(SubStr($t,2),$lf)
EndFunction
Function QS($a)
DIM $b[32],$c[32],$d,$e,$f,$g,$h,$i,$j,$k,$l
$b[0]=0
$c[0]=Ubound($a)
$d=0
While $d >=0
$e=$b[$d]
$f=$c[$d]
While $e < $f
$h=$e+($f-$e)/2
$k=$a[$e]
$A[$e]=$A[$h]
$A[$h]=$k
$i=$e+1
$j=$f
$l=0
Do
While ($i<$j) And $A[$e] > $A[$i]
$i=$i+1
Loop
While ($j>=$i) And $A[$j] > $A[$e]
$j=$j-1
Loop
IF $i>=$j
$l=1
Else
$k=$A[$i]
$A[$i]=$A[$j]
$A[$j]=$k
$j=$j-1
$i=$i+1
EndIf
Until $l=1
$k=$a[$e]
$a[$e]=$a[$j]
$a[$j]=$k
$g=$j
If $g-$e <= $f - $g
If $g+1 < $f
$b[$d]=$g+1
$c[$d]=$f
$d=$d+1
EndIf
$f=$g-1
Else
If $g-1 > $e
$b[$d]=$e
$c[$d]=$g-1
$d=$d+1
EndIf
$e=$g+1
EndIf
Loop
$d=$d-1
Loop
$qs=$a
EndFunction
|