#135057 - 2005-03-14 03:27 AM
Re: Generate html report on free space - servers
|
Styles
Fresh Scripter
Registered: 2005-02-22
Posts: 12
|
Here is the code:
Code:
Break on ;this cmd is ok $ServerFile = "C:\admin\Servers.txt" ;this cmd is ok ;-------Information $ = RedirectOutput ("C:\admin\AvailDiskSpace.txt") ; file created in directory ;$nul = Open(1,"$ServerFile") ;nothing happened here ;$server = ReadLine(1) ;nothing happened here ;While $server <> "EndList" ; script froze here - had to Ctrl+C to escape ; $WMI = GetObject("winmgmts:\\" + $server + "\root\cimv2") @Error ; returned all zeros $WMI = GetObject("winmgmts:\\" + "dc-svr-01" + "\root\cimv2") @Error ; returned all zeros $HardDrives = $WMI.ExecQuery("Select * From Win32_LogicalDisk Where DriveType=3") ; returned all zeros For Each $Drive in $HardDrives ;returned all zeros ? " Drive Letter: " $Drive.Name ? " Drive Space: " $Drive.Size ? " Drive Free Space: " $Drive.FreeSpace ;looping on the first server in the list ? Next ;$server = ReadLine(1) Exit
Servers.txt
dc-svr-01 fs-svr-01
|
Top
|
|
|
|
#135058 - 2005-03-14 03:37 AM
Re: Generate html report on free space - servers
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
Try this (i commented-out the redirect for now), what you get ?
Code:
Break on ;this cmd is ok
$ServerFile = "c:\admin\servers.txt" ;this cmd is ok
;-------Information
;$ = RedirectOutput ("C:\admin\AvailDiskSpace.txt") ; file created in directory
$nul = Open(1,$ServerFile) ;nothing happened here
$server = ReadLine(1) ;nothing happened here
While @ERROR = 0
$WMI = GetObject("winmgmts:\\" + $server + "\root\cimv2")
if $WMI
$HardDrives = $WMI.ExecQuery("Select * From Win32_LogicalDisk Where DriveType=3") ; returned all zeros
For Each $Drive in $HardDrives ;returned all zeros
? " Drive Letter: " $Drive.Name
? " Drive Space: " $Drive.Size
? " Drive Free Space: " $Drive.FreeSpace ;looping on the first server in the list
?
Next
Endif
$server = ReadLine(1)
Loop
Exit
I get this:
Quote:
E:\>kix32 t
Drive Letter: C:
Drive Space: 15726702592
Drive Free Space: 5270061056
Drive Letter: E:
Drive Space: 24017813504
Drive Free Space: 11373670400
-Shawn
|
Top
|
|
|
|
#135059 - 2005-03-14 05:24 AM
Re: Generate html report on free space - servers
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
Well here is an overkill version that does the following.
1. Reads a list of systems from a file.
2. Pings it to determine if it is online or not
3. Checks if WMI is functioning correctly
4. Lists the hidden Admin shares excluding Admin$
5. Sorts the list of shares
6. Lists the free space of each hidden share
7. Does not limit to local hard drive as some SAN or other storage may not show as type 3 but the hidden Admin share still remains.
Example output
dc-svr-01 using NetBIOS is not in WINS-DNS
fs-svr-01 using NetBIOS is not in WINS-DNS
ENIGMA C$ 188407332
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
|
|
Top
|
|
|
|
#135060 - 2006-08-22 10:35 PM
Re: Generate html report on free space - servers
|
Jaide
Fresh Scripter
Registered: 2003-03-05
Posts: 32
|
Nice. I've come across another scripts that outputs data into an html format. It list server_name, disk_name, and free_space. I'd like to add a column that list the total disk space on each drive listed in disk_name. I've tried to use GetDiskSpace, but that kept returning an error. Any ideas?
|
Top
|
|
|
|
#135062 - 2006-08-23 04:07 PM
Re: Generate html report on free space - servers
|
Jaide
Fresh Scripter
Registered: 2003-03-05
Posts: 32
|
This is my post. I lost the password to my last reqistration and had to re-register with a new name.
|
Top
|
|
|
|
#135064 - 2006-08-23 10:07 PM
Re: Generate html report on free space - servers
|
Jaide
Fresh Scripter
Registered: 2003-03-05
Posts: 32
|
I get this error - ERROR : IDispatch pointers not allowed in expressions!
|
Top
|
|
|
|
#135066 - 2006-08-23 10:32 PM
Re: Generate html report on free space - servers
|
Jaide
Fresh Scripter
Registered: 2003-03-05
Posts: 32
|
I did see this code listed in the manual but this code already exists in the script. Code:
$WMI = GetObject("winmgmts:\\" + @WKSTA + "\root\cimv2") $HardDrives = $WMI.ExecQuery("Select * From Win32_LogicalDisk Where DriveType=3") For Each $Drive in $HardDrives
Can I have this in the script twice withour causing any errors?
|
Top
|
|
|
|
#135068 - 2006-08-24 10:14 AM
Re: Generate html report on free space - servers
|
Jaide
Fresh Scripter
Registered: 2003-03-05
Posts: 32
|
Not sure I understand what you're saying. Each time I try to use a variable in the script I get an error message.
|
Top
|
|
|
|
#135070 - 2006-08-24 04:32 PM
Re: Generate html report on free space - servers
|
Jaide
Fresh Scripter
Registered: 2003-03-05
Posts: 32
|
Here's is the error -
ERROR : invalid method/function call: too many parameters! Script: C:\servspace_beta1.kix Line : 57
Here is the code -
Code:
For Each $Disk In $DiskSet $co=$co+1 $dname=$Disk.Name $percentfree=Round(DISKSPACE($strComputer,$dname,5)) $percentused=100-$percentfree $rest=$percentfree-5 html($strComputer,$dname,$percentused,$rest,$space)
I added the $space variable but am unsure how to get the script to recognize that variable.
|
Top
|
|
|
|
#135071 - 2006-08-24 04:39 PM
Re: Generate html report on free space - servers
|
Witto
MM club member
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
That is bizar, you only have 7 lines of code and the error is on line 57
|
Top
|
|
|
|
#135073 - 2006-08-24 05:05 PM
Re: Generate html report on free space - servers
|
Jaide
Fresh Scripter
Registered: 2003-03-05
Posts: 32
|
Script up to line 57 -
Code:
Shell "%COMSPEC% /e:1024 /c c:\windows\netview.exe /NTS /BDC /PDC >c:\admin\kix2010_451\servers.txt" If @error<>0 ? "Netview is not found !" ? ? " You have to download netview at (http://www.optimumx.com/download/#NetView)" ? " and place it in this script directory." Quit EndIf
$line="" If Open(3, "c:\admin\kix2010_451\servers.txt") = 0 $x = ReadLine(3) While @ERROR = 0 If $x<>"" $pos=InStr($x," ") $xf=Left($x,$pos-1) If InStr($x,"\\")<>0 $xf=Right($xf,Len($xf)-2) $line=$line+"~~"+$xf EndIf EndIf $x = ReadLine(3) Loop $=Close (3) EndIf $servarray=Split($line,"~~") debhtml() For Each $strComputer in $servarray If $strComputer<>"" ? "In progress for "+$strComputer+" ..." $objWMIService = GetObject("winmgmts:\\"+$strComputer+"\root\cimv2") If @ERROR=0 breakl() $DiskSet = $objWMIService.ExecQuery("select * from Win32_LogicalDisk where DriveType=3") $co=0 For Each $Disk In $DiskSet $co=$co+1 $dname=$Disk.Name $percentfree=Round(DISKSPACE($strComputer,$dname,5)) $percentused=100-$percentfree $rest=$percentfree-5 html($strComputer,$dname,$percentused,$rest,$space)
|
Top
|
|
|
|
#135074 - 2006-08-24 05:36 PM
Re: Generate html report on free space - servers
|
Witto
MM club member
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
Still counting 43 lines Is this YOUR 57th line? Code:
$percentfree=Round(DISKSPACE($strComputer,$dname,5))
|
Top
|
|
|
|
#135075 - 2006-08-24 05:47 PM
Re: Generate html report on free space - servers
|
Jaide
Fresh Scripter
Registered: 2003-03-05
Posts: 32
|
The 57th line is - html($strComputer,$dname,$percentused,$rest,$space)
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 918 anonymous users online.
|
|
|