Styles
(Fresh Scripter)
2005-03-08 09:19 PM
Generate html report on free space - servers

I want to create a script that parses a log file (\\server\drive) and reports the total drive space, used space and free space. I'd like to mail the resulting html file in the script, but can use blat instead.

Co
(MM club member)
2005-03-08 09:35 PM
Re: Generate html report on free space - servers

something like this..




It's NTDoc's script

look at:My Computer Info - for Help Desk use PART 3




Styles
(Fresh Scripter)
2005-03-08 09:44 PM
Re: Generate html report on free space - servers

That looks a little overkill for the information I'm trying to gather. I just need to collect the info and generate a report on that info.

Co
(MM club member)
2005-03-08 09:54 PM
Re: Generate html report on free space - servers

True, But it wasn't meant to be the 100% answer to your question. You can use NTDoc's code to build your own script...

Styles
(Fresh Scripter)
2005-03-08 10:28 PM
Re: Generate html report on free space - servers

Agreed. No harm meant in my reply. I've been looking over the code.

Co
(MM club member)
2005-03-08 11:16 PM
Re: Generate html report on free space - servers

OK...

Styles
(Fresh Scripter)
2005-03-11 06:21 PM
Re: Generate html report on free space - servers

HELP!

Here's what I came up with:

Code:
  ;Variables
$ServerFile = "C:\admin\Servers.txt"

;-------Information
$nul = Open(1,"$ServerFile")
$server = ReadLine(1)
While $server <> "EndList"

$ = RedirectOutput ("C:\admin\AvailDiskSpace.txt")
$WMI = GetObject("winmgmts:\\" + @WKSTA + "\root\cimv2")
$HardDrives = $WMI.ExecQuery("Select * From Win32_LogicalDisk Where DriveType=3")
For Each $Drive in $HardDrives
? " Drive Letter: " $Drive.Name
? " Drive Space: " $Drive.Size
? " Drive Free Space: " $Drive.FreeSpace
?
Next



I have two problems with this (1) the script does not read the text file I've created with the servername and (2) the script runs forever.


ShawnAdministrator
(KiX Supporter)
2005-03-11 06:33 PM
Re: Generate html report on free space - servers

Think you were missing some odds and ends, back at you ...

Code:

break on

$ServerFile = "C:\admin\Servers.txt"

;-------Information

$ = RedirectOutput ("C:\admin\AvailDiskSpace.txt")

$nul = Open(1,"$ServerFile")

$server = ReadLine(1)

while $server <> "EndList"

$WMI = GetObject("winmgmts:\\" + $server + "\root\cimv2")

$HardDrives = $WMI.ExecQuery("Select * From Win32_LogicalDisk Where DriveType=3")

For Each $Drive in $HardDrives
? " Drive Letter: " $Drive.Name
? " Drive Space: " $Drive.Size
? " Drive Free Space: " $Drive.FreeSpace
?
Next

$server = ReadLine(1)

Loop



btw - dont "need" the have an EOF delimiter in your file (endlist), there are other ways to detect EOF.


Styles
(Fresh Scripter)
2005-03-11 08:34 PM
Re: Generate html report on free space - servers

I'm not sure what I'm missing, but the script now outputs Select * From Win32_LogicalDisk Where DriveType=3 over and over again until I hit Ctrl+C. I changed the end Loop to Exit and the script ends, but only reads one line of the servers.txt file.

Les
(KiX Master)
2005-03-11 09:27 PM
Re: Generate html report on free space - servers

After the line:
$WMI = GetObject("winmgmts:\\" + $server + "\root\cimv2")
what does @Error return?

You sure that WMI is installed?


Styles
(Fresh Scripter)
2005-03-12 02:33 PM
Re: Generate html report on free space - servers

That returns a 0 in the output file. Yes WMI in installed on the servers.

Sealeopard
(KiX Master)
2005-03-12 02:35 PM
Re: Generate html report on free space - servers

Might be an issue with un-mached quotes or other syntax problems. Comment out all lines, then re-enable line-by-line and test.

Les
(KiX Master)
2005-03-12 02:48 PM
Re: Generate html report on free space - servers

Then single-step through the code in debug. The console will show each line as it is executed and should give you a clue where to look.

ShawnAdministrator
(KiX Supporter)
2005-03-12 02:50 PM
Re: Generate html report on free space - servers

Try querying your local wks by changing this line back to the way you (originally) had it:

$WMI = GetObject("winmgmts:\\" + $server + "\root\cimv2")

maybe try this as a test:

$WMI = GetObject("winmgmts:\\" + @WKSTA + "\root\cimv2")


Les
(KiX Master)
2005-03-12 02:54 PM
Re: Generate html report on free space - servers

If it works on the first server in the list but not a subsequent one, I still contend it may be an issue with WMI on that particular server. Try hard coding each servername in a snippet of code as a test.

Les
(KiX Master)
2005-03-12 02:55 PM
Re: Generate html report on free space - servers

OH, and another thought... do any of your servernames have hyphens in them?

ShawnAdministrator
(KiX Supporter)
2005-03-12 02:57 PM
Re: Generate html report on free space - servers

ja, or it could be a credentials problem. get your local machine working first.

Les
(KiX Master)
2005-03-12 03:07 PM
Re: Generate html report on free space - servers

When reading from a list, you also have to be real careful not to get any trailing spaces in there.

ShawnAdministrator
(KiX Supporter)
2005-03-12 03:10 PM
Re: Generate html report on free space - servers

ja, if your still having problems after trying these suggestions, might want to re-post your latest code and include the "server list" file as well (or at least some of it anyway) ...

Styles
(Fresh Scripter)
2005-03-14 01:49 AM
Re: Generate html report on free space - servers

Thanks for the help.

I commented out all lines and re-ran the script one line at a time. The completed normally, but only reported the disk space on the first server in servers.txt

Using $WMI = GetObject(“winmgmts\\” + $server + “\root\cimv2”) work locally when I substitute the servername in quotes, i.e. “server01”.

Most servers in my domain have hyphens.

I’m Domain Admin. If the script is executed from my system – it should run OK on all systems in the domain.

I’ll post the code and servers.txt later today.


Les
(KiX Master)
2005-03-14 01:59 AM
Re: Generate html report on free space - servers

In your example, you have curly (smart) quotes. Please tell me you didn't copy paste that from your script! If the server names have hyphens, they should be in quotes. Just because the script works on one computer it doesn't mean it will work on all computers. If you have trailing spaces in your list, it will bite.

Styles
(Fresh Scripter)
2005-03-14 03:27 AM
Re: Generate html report on free space - servers

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


ShawnAdministrator
(KiX Supporter)
2005-03-14 03:37 AM
Re: Generate html report on free space - servers

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


NTDOCAdministrator
(KiX Master)
2005-03-14 05:24 AM
Re: Generate html report on free space - servers

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



Jaide
(Fresh Scripter)
2006-08-22 10:35 PM
Re: Generate html report on free space - servers

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?

NTDOCAdministrator
(KiX Master)
2006-08-23 02:45 AM
Re: Generate html report on free space - servers

Well please don't Hijack a topic, rather start your own and put a link to this post if you want.

Basically you would look up the error message and try to correct the error.

From a CMD.EXE console. NET HELPMSG will show you the error meaning.


Jaide
(Fresh Scripter)
2006-08-23 04:07 PM
Re: Generate html report on free space - servers

This is my post. I lost the password to my last reqistration and had to re-register with a new name.

NTDOCAdministrator
(KiX Master)
2006-08-23 08:09 PM
Re: Generate html report on free space - servers

Okay, no problem.

So what is the error message you get when you run GetDiskSpace( )

$Result = GetDiskSpace( "C:\" )


Jaide
(Fresh Scripter)
2006-08-23 10:07 PM
Re: Generate html report on free space - servers

I get this error -
ERROR : IDispatch pointers not allowed in expressions!


LonkeroAdministrator
(KiX Master Guru)
2006-08-23 10:16 PM
Re: Generate html report on free space - servers

sorry, but that is just not possible.

Jaide
(Fresh Scripter)
2006-08-23 10:32 PM
Re: Generate html report on free space - servers

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?


NTDOCAdministrator
(KiX Master)
2006-08-24 02:01 AM
Re: Generate html report on free space - servers

Potentially yes, but there should be no reason to have that. Run it once and asign the returned data to a variable.

Then when you need / want the data check/print the variable you assigned it to.


Jaide
(Fresh Scripter)
2006-08-24 10:14 AM
Re: Generate html report on free space - servers

Not sure I understand what you're saying. Each time I try to use a variable in the script I get an error message.

Richard H.Administrator
(KiX Supporter)
2006-08-24 10:33 AM
Re: Generate html report on free space - servers

Post details of the actual error, otherwise we won't be able to help.

Jaide
(Fresh Scripter)
2006-08-24 04:32 PM
Re: Generate html report on free space - servers

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.


Witto
(MM club member)
2006-08-24 04:39 PM
Re: Generate html report on free space - servers

That is bizar, you only have 7 lines of code and the error is on line 57

Witto
(MM club member)
2006-08-24 04:53 PM
Re: Generate html report on free space - servers

If DiskSpace() is the UDF written by Jens, I think it only accepts 2 optional parameters

Jaide
(Fresh Scripter)
2006-08-24 05:05 PM
Re: Generate html report on free space - servers

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)



Witto
(MM club member)
2006-08-24 05:36 PM
Re: Generate html report on free space - servers

Still counting 43 lines
Is this YOUR 57th line?
Code:
         $percentfree=Round(DISKSPACE($strComputer,$dname,5))         



Jaide
(Fresh Scripter)
2006-08-24 05:47 PM
Re: Generate html report on free space - servers

The 57th line is -
html($strComputer,$dname,$percentused,$rest,$space)


Witto
(MM club member)
2006-08-24 06:37 PM
Re: Generate html report on free space - servers

Well, I am surprised
Code:

DISKSPACE($strComputer,$dname,5)


is not giving an error because IMHO it only supports 2 optional parameters.
I also think you have to show more about the html() function as most probably it will not support 5 or more parameters.


Les
(KiX Master)
2006-08-24 07:10 PM
Re: Generate html report on free space - servers

The 57th line is an unhandled function. What does it return to hte console?

Jaide
(Fresh Scripter)
2006-08-25 05:20 PM
Re: Generate html report on free space - servers

I tried to correct the variable and got this error -

ERROR : IDispatch pointers not allowed in expressions!

The code is below (lines 15 thru 69)

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
$space=GetDiskSpace($DiskSet)
html($strComputer,$dname,$percentused,$rest,$space)
Next
ftabl()
Else
? $strcomputer+" WMI not installed."
breakl()
offline($strcomputer)
ftabl()
EndIf

EndIf
Next



Sealeopard
(KiX Master)
2006-08-27 10:03 PM
Re: Generate html report on free space - servers

Your error is in line
Code:

$space=GetDiskSpace($DiskSet)


as you're supplying an array/object into the GETDISKSPACE() function.

Use DEBUG ON to properly debug your scripts.


Jaide
(Fresh Scripter)
2006-08-28 05:06 AM
Re: Generate html report on free space - servers

I can't figure this out. The script outputs

In progress for Server ...Select * from Win32_LogicalDisk where DeviceID=':'

on every line. If I remove the line I do not get the desired output from GetFreeSpace function. If you can tell me where I've gone wrong I'd appreciate the help.

Lines 007 - 274

Code:
  
;===============================================================================================
;
; DEPENDENCIES: WMI on servers, netview->(http://www.optimumx.com/download/#NetView)
;
;===============================================================================================
Break on


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
$free-GetFreeSpace($WS,$Drive)
html($strComputer,$dname,$percentused,$rest,$free)
Next
ftabl()
Else
? $strcomputer+" WMI not installed."
breakl()
offline($strcomputer)
ftabl()
EndIf

EndIf
Next

finhtml()

$IE = CreateObject("InternetExplorer.Application")
$IE.Navigate(@SCRIPTDIR+"\resserv.html")
$IE.Visible = 1


;*************************************************
Function debhtml()

Del ".\resserv.html"
$=Open( 3 , ".\resserv.html" , 5 )
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , "
"+@CRLF)
$x = WriteLine( 3 , "

Disk used for servers on domain "+@DOMAIN+"

"+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , "Unfortunately the non Windows servers could not be query
"+@CRLF)
$x = WriteLine( 3 , "and report the line 'No WMI or server offline' :(

"+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$=Close (3)

EndFunction
;*************************************************
Function html($server,$drive,$percentfree,$rest,$free)

$=Open( 3 , ".\resserv.html" , 5 )
$x = WriteLine( 3 , "
ServerUsed Avail-Space
"+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ''+@CRLF)
$x = WriteLine( 3 , ''+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ''+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$=Close (3)

EndFunction
;*************************************************
Function offline($server)

$=Open( 3 , ".\resserv.html" , 5 )
$x = WriteLine( 3 , "
'+$server+':Drive '+$drive+' '+$percentfree+' % '+$free+'
"+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$=Close (3)

EndFunction
;*************************************************
Function breakl()
$=Open( 3 , ".\resserv.html" , 5 )
$x = WriteLine( 3 , '
'+@CRLF)
$=Close (3)
EndFunction
;*************************************************
Function ftabl()

$=Open( 3 , ".\resserv.html" , 5 )
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , "
"+$server+":No WMI or server offline
"+@CRLF)
$=Close (3)

EndFunction
;*************************************************
Function finhtml()

$=Open( 3 , ".\resserv.html" , 5 )
$x = WriteLine( 3 , '
'+@CRLF)
$x = WriteLine( 3 , "
"+@CRLF)
$x = WriteLine( 3 , "
"+@CRLF)
$x = WriteLine( 3 , "Edition: " + @DATE + " - at " + @TIME+" by "+@FULLNAME+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$=Close (3)

EndFunction
;*************************************************
;FUNCTION DiskSpace
;
;ACTION returns the available disk space on a drive
;
;AUTHOR Jens Meyer (sealeopard@usa.net)
;
;CONTRIBUTORS NTDOC, Radimus, kholm
;
;VERSION 1.4 (added PetaByte, Percentage as unit sizes)
; 1.3 (shortened code, included UNCs as valid input)
; 1.2 (added optional drive and optional units)
; 1.1
;
;DATE CREATED 2001/12/18
;
;DATE MODIFIED 2003/07/06
;
;KIXTART 4.21
;
;SYNTAX DISKSPACE([DRIVE, FORMAT])
;
;PARAMETERS DRIVE
; optional driveletter, directory, or UNC (defaults to system drive)
;
; FORMAT
; optional parameter indicating the units to be used when returning the
; available disk space
; 0 = KB (KiloByte, default)
; 1 = MB (MegaByte)
; 2 = GB (GigaByte)
; 3 = TB (TeraByte)
; 4 = PB (PetaByte)
; 5 = % (percentage total diskspace, does not support UNCs)
;
;RETURNS available diskspace
;
;REMARKS none
;
;DEPENDENCIES WMI (only for FORMAT = 5)
;
;EXAMPLE $rc=DISKSPACE()
;
;
Function diskspace($computer,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}!\\'+$computer+'\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:
; GetFreeSpace()
;
;Author:
; Kholm
;
;Version:
; 1.0 (17th of september 2003)
;
;Action: Returns available space on diskdrives on remote workstations (where the server service is NOT started)
;
;Syntax GetFreeSpace($WS,$Drive)
;
;Parameters:
; - $WS = Name of remote workstation
; - $Drive = Driveletter for drive to be checked
;
;Returns: Free space on selected ws/drive
;
;Dependencies: WMI
;
;Remarks:
; OBSERVE: You should use the KiXtart function: GetDiskSpace('\\' + $Computer + '\' + $Drive + '$$')
; If the server service is startet on the workstation you want to check,
;
;Example:
; $Free = GetFreeSpace('WS02','C')
; 'Free space on drive C: on workstation WS02 is: ' + $Free

Function GetFreeSpace($Computer,$Drive)
Dim $oComputer,$cItems,$oItem
$oComputer = GetObject("winmgmts:\\" + $Computer + "\root\cimv2")
$cItems = $oComputer.ExecQuery("Select * from Win32_LogicalDisk where DeviceID='$Drive:'")
For Each $oItem In $cItems
$GetFreeSpace = 0.0009765625 * $oItem.FreeSpace
Next
EndFunction



AllenAdministrator
(KiX Supporter)
2006-08-28 07:13 AM
Re: Generate html report on free space - servers

See if this helps...

Code:
 
Function GetFreeSpace($Computer,$Drive)
Dim $oComputer,$cItems,$oItem
$oComputer = GetObject("winmgmts:\\" + $Computer + "\root\cimv2")
$cItems = $oComputer.ExecQuery("Select * from Win32_LogicalDisk where DeviceID='" + $Drive + ":'")
For Each $oItem In $cItems
$GetFreeSpace = 0.0009765625 * $oItem.FreeSpace
Next
EndFunction



NTDOCAdministrator
(KiX Master)
2006-08-28 10:58 AM
Re: Generate html report on free space - servers

Quote:

In progress for Server ...Select * from Win32_LogicalDisk where DeviceID=':'




1. WMI is either broken or you don't have access to it on one or more systems.
2. Call using something like a var in a string or feeding an array instead of a string, or similar.

I would try adding this UDF to the top of your script right about after this:
If $strComputer<>""

WMIConfirm($strComputer)


WMIConfirm() - Confirm access to WMI
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=114011


NTDOCAdministrator
(KiX Master)
2006-08-28 01:28 PM
Re: Generate html report on free space - servers

Okay I think you may be making a mistake in the file reading, or at least making it a bit more difficult.

Try modifying your script to fit into this structure.
Notice the /b which will give it a bare format
that is desired for scripting the names.

Also get and place the ReadFile UDF into your script.

Dim $ServerList, $strComputer, $Servers
Dim $WMI
$ServerList = @ScriptDir + '\' + 'servers.txt'
Shell '%COMSPEC% /c netview.exe /NTS /BDC /PDC /b > ' + $ServerList
If @ERROR
"Netview is not found !" ??
"You have to download netview at (http://www.optimumx.com/download/#NetView)" ?
"and place it in this script directory." ?
Quit @ERROR
EndIf
debhtml()
$Servers = ReadFile($ServerList)
For Each $strComputer In $Servers
$strComputer = Trim(Join(Split($strComputer,'\\'),''))
If $strComputer<>""
"In progress for " + $strComputer + " ..." ?
$WMI = WMIConfirm($strComputer)
If $WMI > 0
'WMI on: ' + $strComputer + ' working okay' ?
Else
'Unable to access the ' + $strComputer + ' due to WMI error' ?
EndIf
EndIf
Next


Then to make your file write faster you can change your WriteLine to something like this (untested in working code)

Function debhtml()
Dim $Open, $x, $Close
If Exist(".\resserv.html")
Del ".\resserv.html"
EndIf
$Open = Open(3,".\resserv.html",5)
$x = "<html>"+@CRLF
$x = $x + "<head>"+@CRLF
$x = $x + "<STYLE>"+@CRLF
$x = $x + "BODY {"+@CRLF
$x = $x + " font-size:10 pt;"+@CRLF
$x = $x + " font-family: Verdana;"+@CRLF
$x = $x + "}"+@CRLF
$x = $x + "H3 {"+@CRLF
$x = $x + " font-size:12 pt;"+@CRLF
$x = $x + " font-family: Verdana;"+@CRLF
$x = $x + "}"+@CRLF
$x = $x + "TH {"+@CRLF
$x = $x + " font-family : Verdana;"+@CRLF
$x = $x + " font-size : 12;"+@CRLF
$x = $x + "}"+@CRLF
$x = $x + "TD {"+@CRLF
$x = $x + " font-family : Verdana;"+@CRLF
$x = $x + " font-size : 12;"+@CRLF
$x = $x + "}"+@CRLF
$x = $x + "</STYLE>"+@CRLF
$x = $x + "</head>"+@CRLF
$x = $x + "<body>"+@CRLF
$x = $x + "<br>"+@CRLF
$x = $x + "<H3>Disk used for servers on domain "+@DOMAIN+"</H3>"+@CRLF
$x = $x + ""+@CRLF
$x = $x + "Unfortunately the non Windows servers could not be query<br>"+@CRLF
$x = $x + "and report the line 'No WMI or server offline' : (<br><br></font>"+@CRLF
$x = $x + "<Table border=0>"+@CRLF
$x = $x + "<TR>"+@CRLF
$x = $x + "<TD width=120>Server</TD>"+@CRLF
$x = $x + "<TD width=100>Used</TD>"+@CRLF
$x = $x + "<TD width=100 bgcolor=gray> </TD>"+@CRLF
$x = $x + "<TD width=120>Avail-Space</TD>"+@CRLF
$x = $x + "</TR>"+@CRLF
$x = WriteLine(3,$x)
$Close = Close(3)
EndFunction

 

I'm 99.9% sure that you're feeding a blank or non machine name to the rest of your functions and then the GetObject
is failing but since it doesn't know to end there it keeps
generating bogus output.

Use the above coding method and I'm sure you'll end up with working code.


NTDOCAdministrator
(KiX Master)
2006-08-28 08:55 PM
Re: Generate html report on free space - servers

Oops... That code will not work for you either as NETVIEW also returns the description even with the /b switch.

Well you get the idea. There are many ways to get the list and pinging them first as in one of the original scripts I posted for you. That should speeds things up for systems that not online. Systems can show in the NETVIEW or NET VIEW list for 15 minutes or so after they have been shut down.

Anyways... get a list of computer names and edit the file so that ONLY the names are in it with nothing else and then use WMIConfirm as shown and you should be good to go.
You may want to add more logging to file or something to see when or where a system could not be contacted.


Jaide
(Fresh Scripter)
2006-08-28 10:36 PM
Re: Generate html report on free space - servers

NTDOC,

Thanks for the help with the script. I have one question - where do i replace the code ih the two sections above? I noticed the script that I posted did not post as expected. It looks like a few function sections got repeated. I'll try posting again.

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
$free-GetFreeSpace($WS,$Drive)
html($strComputer,$dname,$percentused,$rest,$free)
Next
ftabl()
Else
? $strcomputer+" WMI not installed."
breakl()
offline($strcomputer)
ftabl()
EndIf

EndIf
Next

finhtml()

$IE = CreateObject("InternetExplorer.Application")
$IE.Navigate(@SCRIPTDIR+"\resserv.html")
$IE.Visible = 1
;*************************************************

Function debhtml()
Dim $Open, $x, $Close
If Exist(".\resserv.html")
Del ".\resserv.html"
EndIf
$Open = Open(3,".\resserv.html",5)
$x = ""+@CRLF
$x = $x + ""+@CRLF
$x = $x + ""+@CRLF
$x = $x + ""+@CRLF
$x = $x + ""+@CRLF
$x = $x + "
"+@CRLF
$x = $x + "

Disk used for servers on domain "+@DOMAIN+"

"+@CRLF
$x = $x + ""+@CRLF
$x = $x + "Unfortunately the non Windows servers could not be query
"+@CRLF
$x = $x + "and report the line 'No WMI or server offline' : (

"+@CRLF
$x = $x + ""+@CRLF
$x = $x + ""+@CRLF
$x = $x + ""+@CRLF
$x = $x + ""+@CRLF
$x = $x + ""+@CRLF
$x = $x + ""+@CRLF
$x = $x + ""+@CRLF
$x = WriteLine(3,$x)
$Close = Close(3)
EndFunction

;*************************************************

Function html($server,$drive,$percentfree,$rest,$free)

$=Open( 3 , ".\resserv.html" , 5 )
$x = WriteLine( 3 , "
ServerUsed Avail-Space
"+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ''+@CRLF)
$x = WriteLine( 3 , ''+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ''+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$=Close (3)

EndFunction
;*************************************************
Function offline($server)

$=Open( 3 , ".\resserv.html" , 5 )
$x = WriteLine( 3 , "
'+$server+':Drive '+$drive+' '+$percentfree+' % '+$free+'
"+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$=Close (3)

EndFunction
;*************************************************
Function breakl()
$=Open( 3 , ".\resserv.html" , 5 )
$x = WriteLine( 3 , '
'+@CRLF)
$=Close (3)
EndFunction
;*************************************************
Function ftabl()

$=Open( 3 , ".\resserv.html" , 5 )
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , "
"+$server+":No WMI or server offline
"+@CRLF)
$=Close (3)

EndFunction
;*************************************************
Function finhtml()

$=Open( 3 , ".\resserv.html" , 5 )
$x = WriteLine( 3 , '
'+@CRLF)
$x = WriteLine( 3 , "
"+@CRLF)
$x = WriteLine( 3 , "
"+@CRLF)
$x = WriteLine( 3 , "Edition: " + @DATE + " - at " + @TIME+" by "+@FULLNAME+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$x = WriteLine( 3 , ""+@CRLF)
$=Close (3)

EndFunction
;*************************************************
;FUNCTION DiskSpace
;
;ACTION returns the available disk space on a drive
;
;AUTHOR Jens Meyer (sealeopard@usa.net)
;
;CONTRIBUTORS NTDOC, Radimus, kholm
;
;VERSION 1.4 (added PetaByte, Percentage as unit sizes)
; 1.3 (shortened code, included UNCs as valid input)
; 1.2 (added optional drive and optional units)
; 1.1
;
;DATE CREATED 2001/12/18
;
;DATE MODIFIED 2003/07/06
;
;KIXTART 4.21
;
;SYNTAX DISKSPACE([DRIVE, FORMAT])
;
;PARAMETERS DRIVE
; optional driveletter, directory, or UNC (defaults to system drive)
;
; FORMAT
; optional parameter indicating the units to be used when returning the
; available disk space
; 0 = KB (KiloByte, default)
; 1 = MB (MegaByte)
; 2 = GB (GigaByte)
; 3 = TB (TeraByte)
; 4 = PB (PetaByte)
; 5 = % (percentage total diskspace, does not support UNCs)
;
;RETURNS available diskspace
;
;REMARKS none
;
;DEPENDENCIES WMI (only for FORMAT = 5)
;
;EXAMPLE $rc=DISKSPACE()
;
;
Function diskspace($computer,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}!\\'+$computer+'\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:
; GetFreeSpace()
;
;Author:
; Kholm
;
;Version:
; 1.0 (17th of september 2003)
;
;Action: Returns available space on diskdrives on remote workstations (where the server service is NOT started)
;
;Syntax GetFreeSpace($WS,$Drive)
;
;Parameters:
; - $WS = Name of remote workstation
; - $Drive = Driveletter for drive to be checked
;
;Returns: Free space on selected ws/drive
;
;Dependencies: WMI
;
;Remarks:
; OBSERVE: You should use the KiXtart function: GetDiskSpace('\\' + $Computer + '\' + $Drive + '$$')
; If the server service is startet on the workstation you want to check,
;
;Example:
; $Free = GetFreeSpace('WS02','C')
; 'Free space on drive C: on workstation WS02 is: ' + $Free

Function GetFreeSpace($Computer,$Drive)
Dim $oComputer,$cItems,$oItem
$oComputer = GetObject("winmgmts:\\" + $Computer + "\root\cimv2")
$cItems = $oComputer.ExecQuery("Select * from Win32_LogicalDisk where DeviceID='" + $Drive + ":'")
For Each $oItem In $cItems
$GetFreeSpace = 0.0009765625 * $oItem.FreeSpace
Next
EndFunction

;Function GetFreeSpace($Computer,$Drive)
; Dim $oComputer,$cItems,$oItem
; $oComputer = GetObject("winmgmts:\\" + $Computer + "\root\cimv2")
; $cItems = $oComputer.ExecQuery("Select * from Win32_LogicalDisk where DeviceID='$Drive:'")
; For Each $oItem In $cItems
; $GetFreeSpace = 0.0009765625 * $oItem.FreeSpace
; Next
;EndFunction




NTDOCAdministrator
(KiX Master)
2006-08-29 12:00 AM
Re: Generate html report on free space - servers

You can't post it as is because UBB won't allow you to post the html portion of your code as is. It converts it on the fly.

Regardless. I think you need to get rid of this code
Code:
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



and modify a text file that has ALL the names of the Servers in
it already in a bare format like this:

SERVER1
SERVER2
SERVER3
etc...

What NETVIEW is giving you is something more like this
\\SERVER1 The main webserver
\\SERVER2 Corporate Finance
etc...

So the comments section screws up the rest of the code.
If you print to screen you'd see some garbage which is what the rest of the code sees and can't contact a server named
Corporate or Finance etc...

Try just a ReadFile UDF as shown in a test script and make sure the output on screen just gives back your Server names.
Or if you don't have that many you could even list them in the actual code
Code:
$Servers = Split('server1,server2,server3,server4',',')
For Each $Server In $Servers
If $Server
$Server ?
EndIf
Next



Then along with the WMIConfirm you should be good to go or at least see where other issues might be.


NTDOCAdministrator
(KiX Master)
2006-08-29 05:25 AM
Re: Generate html report on free space - servers

Okay, so many errors so little time to fix.

I've restructured and re-written most of this script except your HTML sections.
It should run right out the gate now, but won't be what you're looking for.

I'm guessing that when/where/how you're opening/writing/closing the HTML file is not
optimal and is causing improperly coded information.

I've re-written how it get's disk space but I'm not 100% sure of how you're wanting it displayed.

So you can take it from here, or maybe if you're lucky Jooel will help out on it as he seems to
like doing the HTML type code as well.
Then fix that portion and it should actually be a nice little snippet of code.

If you can't get it going or if no one else will help I'll try to get it working, just so
I can run it myself once in a while.

I might have a scope issue there as well, just don't have time to decipher the whole script to that level right now.



Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')

Global $ServerList, $strComputer, $Servers
Dim $WMI, $objWMIService, $Disk, $DiskSet
Global $dname
Global $Free, $Free0, $Free1, $Free2
Dim $IE
$ServerList = @ScriptDir + '\' + 'servers.txt'
Shell '%COMSPEC% /c netview.exe /NTS /BDC /PDC /b > ' + $ServerList
If @ERROR
"Netview is not found !" ??
"You have to download netview at (http://www.optimumx.com/download/#NetView)" ?
"and place it in this script directory." ?
Quit @ERROR
EndIf
debhtml()
$Servers = ReadFile($ServerList)
For Each $strComputer In $Servers
$strComputer = SubStr($strComputer,3,InStr($strComputer,' ')-3)
If $strComputer<>""
"In progress for " + $strComputer + " ..." ?
$WMI = WMIConfirm($strComputer)
If $WMI > 0
$objWMIService = GetObject("winmgmts:\\"+$strComputer+"\root\cimv2")
breakl()
$DiskSet = $objWMIService.ExecQuery("select * from Win32_LogicalDisk where DriveType=3")
For Each $Disk In $DiskSet
$dname = $Disk.Name
$Free0 = "" $Free1 = "" $Free2 = ""
$Free = GetDiskFreeSpace($strComputer,$dname)
$Free0 = $Free[0]
$Free1 = $Free[1]
$Free2 = $Free[2]
html($strComputer,$dname,$Free1,$Free0,$Free2)
Next
ftabl()
Else
'Unable to access ' + $strComputer + ' due to WMI error' ?
breakl()
offline($strcomputer)
ftabl()
EndIf
EndIf
Next
finhtml()
$IE = CreateObject("InternetExplorer.Application")
$IE.Navigate(@SCRIPTDIR+"\resserv.html")
$IE.Visible = 1
QUIT 1

Function WMIConfirm(optional $sComputer)
Dim $objWMIService, $objWMISetting, $colWMISettings
$sComputer = IIf(Not $sComputer,'','\\'+Join(Split($sComputer,'\'),'',3)+'\')
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!"+$sComputer+'root\cimv2')
; Failed - return 0 and exit with error value
If @ERROR
$WMIConfirm = 0
Exit Val('&' + Right(DecToHex(@ERROR), 4))
EndIf
$colWMISettings = $objWMIService.ExecQuery("Select * from Win32_WMISetting")
For Each $objWMISetting In $colWMISettings
$WMIConfirm = $objWMISetting.BuildVersion
Next
Exit 0
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 debhtml()
Dim $Handle, $Open, $Data, $Close
If Exist(".\resserv.html")
Del ".\resserv.html"
EndIf
$Handle = FreeFileHandle()
If $Handle > 0
$Open = Open($Handle,".\resserv.html",5)
$Data = "<html>"+@CRLF
$Data = $Data + "<head>"+@CRLF
$Data = $Data + "<STYLE>"+@CRLF
$Data = $Data + "BODY {"+@CRLF
$Data = $Data + " font-size:10 pt;"+@CRLF
$Data = $Data + " font-family: Verdana;"+@CRLF
$Data = $Data + "}"+@CRLF
$Data = $Data + "H3 {"+@CRLF
$Data = $Data + " font-size:12 pt;"+@CRLF
$Data = $Data + " font-family: Verdana;"+@CRLF
$Data = $Data + "}"+@CRLF
$Data = $Data + "TH {"+@CRLF
$Data = $Data + " font-family : Verdana;"+@CRLF
$Data = $Data + " font-size : 12;"+@CRLF
$Data = $Data + "}"+@CRLF
$Data = $Data + "TD {"+@CRLF
$Data = $Data + " font-family : Verdana;"+@CRLF
$Data = $Data + " font-size : 12;"+@CRLF
$Data = $Data + "}"+@CRLF
$Data = $Data + "</STYLE>"+@CRLF
$Data = $Data + "</head>"+@CRLF
$Data = $Data + "<body>"+@CRLF
$Data = $Data + "<br>"+@CRLF
$Data = $Data + "<H3>Disk space usage for servers on domain "+@DOMAIN+"</H3>"+@CRLF
$Data = $Data + ""+@CRLF
$Data = $Data + "Unfortunately the non Windows servers could not be queried<br>"+@CRLF
$Data = $Data + "and be reported on 'No WMI or server offline' : (<br><br></font>"+@CRLF
$Data = $Data + "<Table border=0>"+@CRLF
$Data = $Data + "<TR>"+@CRLF
$Data = $Data + "<TD width=120>Server</TD>"+@CRLF
$Data = $Data + "<TD width=100>Used</TD>"+@CRLF
$Data = $Data + "<TD width=100 bgcolor=gray> </TD>"+@CRLF
$Data = $Data + "<TD width=120>Avail-Space</TD>"+@CRLF
$Data = $Data + "</TR>"+@CRLF
$Data = WriteLine($Handle, $Data)
$Close = Close($Handle)
EndIf
EndFunction

Function html($server,$drive,$Free1,$Free0,$Free2)
Dim $Handle, $Open, $Data, $Close
$Handle = FreeFileHandle()
If $Handle > 0
$Open = Open($Handle,".\resserv.html",5)
$Data = "<Table border=0>"+@CRLF
$Data = $Data + "<TR>"+@CRLF
$Data = $Data + '<TD width=120>'+$server+':</TD>'+@CRLF
$Data = $Data + '<TD width=100>Drive '+$drive+' '+$free1+' %</TD>'+@CRLF
$Data = $Data + "<TD width="+$free0+" bgcolor=red> </TD>"+@CRLF
$Data = $Data + "<TD width="+$Free2+" bgcolor=green></TD>"+@CRLF
$Data = $Data + '<TD width=120>'+$Free1+'</TD>'+@CRLF
$Data = $Data + "<TR>"+@CRLF
$Data = WriteLine($Handle, $Data)
$Close = Close($Handle)
EndIf
EndFunction

Function offline($server)
Dim $Handle, $Open, $Data, $Close
$Handle = FreeFileHandle()
If $Handle > 0
$Open = Open($Handle,".\resserv.html",5)
$Data = "<Table border=0>"+@CRLF
$Data = $Data + "<TR>"+@CRLF
$Data = $Data + "<TD width=120>"+$server+":</TD>"+@CRLF
$Data = $Data + "<TD width=200>No WMI or server offline</font></TD>"+@CRLF
$Data = WriteLine($Handle, $Data)
$Close = Close($Handle)
EndIf
EndFunction

;*******
Function breakl()
Dim $Handle, $Open, $Data, $Close
$Handle = FreeFileHandle()
If $Handle > 0
$Open = Open($Handle,".\resserv.html",5)
$Data = WriteLine($Handle,'<hr width="100%" size="1" Color="#FFFFFF">'+@CRLF)
$Close = Close($Handle)
EndIf
EndFunction
;*************************************************
Function ftabl()
Dim $Handle, $Open, $Data, $Close
$Handle = FreeFileHandle()
If $Handle > 0
$Open = Open($Handle,".\resserv.html",5)
$Data = "</TR>"+@CRLF
$Data = $Data + "</Table>"+@CRLF
$Data = WriteLine($Handle, $Data)
$Close = Close($Handle)
EndIf
EndFunction
;*************************************************
Function finhtml()
Dim $Handle, $Open, $Data, $Close
$Handle = FreeFileHandle()
If $Handle > 0
$Open = Open($Handle,".\resserv.html",5)
$Data = '<hr width="100%" size="1" Color="#FFFFFF">'+@CRLF
$Data = $Data + "<br>"+@CRLF
$Data = $Data + "<br>"+@CRLF
$Data = $Data + "Edition: " + @DATE + " - at " + @TIME+" by "+@FULLNAME+@CRLF
$Data = $Data + "</body>"+@CRLF
$Data = $Data + "</html>"+@CRLF
$Data = WriteLine($Handle, $Data)
$Close = Close($Handle)
EndIf
EndFunction

Function GetDiskFreeSpace($sComputer,$Drive)
Dim $objWMIService, $colDisks, $objDisk
Dim $intFreeSpace, $intTotalSpace, $pctFreeSpace, $intUsed
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $sComputer + "\root\cimv2")
$colDisks = $objWMIService.ExecQuery('Select * from Win32_LogicalDisk Where DeviceID = '+"'"+$Drive+"'")
For Each $objDisk in $colDisks
$intFreeSpace = CDBL($objDisk.FreeSpace)
$intTotalSpace = CDBL($objDisk.Size)
$pctFreeSpace = FormatNumber(($intFreeSpace / $intTotalSpace * 100),2)
$intFreeSpace = FormatNumber($intFreeSpace,0,,-2)
$intUsed = CDBL(100) - $pctFreeSpace
Next
$GetDiskFreeSpace = $pctFreeSpace, $intUsed, $intFreeSpace
Exit @ERROR
EndFunction


Benny69
(MM club member)
2006-08-29 06:18 AM
Re: Generate html report on free space - servers

Holly Crap Doc! You Rock!

NTDOCAdministrator
(KiX Master)
2006-08-29 06:22 AM
Re: Generate html report on free space - servers

Thanks Benny,

Amazing what you can do while you're on hold with Microsoft on the phone.

Not 100% functional but at least you can run it and see what he's TRYING to do now.


Jaide
(Fresh Scripter)
2006-08-29 03:59 PM
Re: Generate html report on free space - servers

Thanks DOC - I appreciate the time and effort.

Jaide
(Fresh Scripter)
2006-08-29 04:08 PM
Re: Generate html report on free space - servers

WHOA!

The script runs much faster now. It used to take 4-5 minutes to process, now it's around a minute. The used space % and free space # reports the same values. The html code needs some work. Thanks for making this easier to read.


NTDOCAdministrator
(KiX Master)
2006-08-30 03:11 AM
Re: Generate html report on free space - servers

You're welcome. Yeah, it still needs work. If you do fix it please post your fixed version so we can all check it out.

If not, then maybe if I can find time, I'll look at fixing it - but no promises.

There were 3 big issues in the code overall (not including the html code)

1. Not reading the server names correctly
2. Not properly checking for WMI operation
3. Not calling UDFs with the correct parameters.

Glad you to be of assistance.


NTDOCAdministrator
(KiX Master)
2006-08-30 03:13 AM
Re: Generate html report on free space - servers

Oh... to give credit where credit is due.

This code snipet is from Glenn Barnas. I was trying to do it with Split but still be able to not call empty elements.
This code from Glenn is much easier to use in this situation I think.

Code:
$strComputer = SubStr($strComputer,3,InStr($strComputer,' ')-3)




And after all this my star value is still at 4 due to someone posting a low score. (only takes one, dumb board algorithm). But my rates are still only 34 - no one seems to use the rating even though it's in Shawn's signature.




Gargoyle
(MM club member)
2006-08-30 09:06 AM
Re: Generate html report on free space - servers

If it is any consolation doc, I believe you deserve at least a 7 star rating ( *******)

LonkeroAdministrator
(KiX Master Guru)
2006-08-31 12:45 AM
Re: Generate html report on free space - servers

so, why does this thing require netview?

NTDOCAdministrator
(KiX Master)
2006-08-31 01:17 AM
Re: Generate html report on free space - servers

It doesn't per say, but it has switches to choose between different types of returned systems.

NET VIEW does not.


You can modify your file and rem out the SHELL line to test it out.


NTDOCAdministrator
(KiX Master)
2006-08-31 05:53 AM
Re: Generate html report on free space - servers

Here is difference Jooel.

http://www.optimumx.com/
http://www.optimumx.com/download/

Quote:


Network View - version 1.20
 
Displays a list of all machines visible in the specified domain, based on role.
 
 
The syntax of this command is:
 
netview [/NTW] [/NTS] [/PDC] [/BDC] [/PRINT] [/RAS] [/SQL] [/TIME] [/TS]
[/9x] [/HEX:0xXXXXXXXX] [/DOMAIN:domain] [/T] [/TABS]

Multiple switches can be specified, separate each with a space.
 
/NTW will include NT/2000/XP workstations.
/NTS will include NT/2000/.NET servers.
/PDC will include NT/2000/.NET primary domain controllers.
/BDC will include NT backup domain controllers.
/PRINT will include Print queue servers.
/RAS will include Remote Access Servers.
/SQL will include Microsoft SQL Servers.
/TIME will include all Time sources.
/TS will include all Terminal Servers.
/9x will include Windows 95/98/ME systems. (Only if sharing has been enabled.)
/HEX: allows you to specify your own bit mask. Use /HEX: /? for more details.
 
/DOMAIN: allows you to specify a different domain or workgroup.
/T also displays the primary machine type (Server, Workstation, PDC, etc.)
/B displays the output in bare format (useful when scripting)
/TABS separates columns with tabs instead of spaces (useful when importing)
 
 
An argument of /? or -? displays this syntax and always returns 1.
A successful completion will return 0.
 
 
Copyright 2000-2001 Marty List, OptimumX@usa.net
 



 
 
 
Quote:

The syntax of this command is:


NET VIEW
[\\computername [/CACHE] | /DOMAIN[:domainname]]
NET VIEW /NETWORK:NW [\\computername]
 





Jaide
(Fresh Scripter)
2006-09-04 01:33 AM
Re: Generate html report on free space - servers

I have a problem with numbers under 1, i.e. 0.9. The script computes those numbers to 15 decimal places. I used the ROUND() command for numbers above 1.0 - seems to work pretty well. Any idea how to limit the amount of decimal spaces?

NTDOCAdministrator
(KiX Master)
2006-09-04 05:52 AM
Re: Generate html report on free space - servers

FormatNumber( )

I'll try to take a look at the whole thing further this week though and maybe update the UDF I setup for the script.


Jaide
(Fresh Scripter)
2006-09-15 09:58 PM
Re: Generate html report on free space - servers

DOC - I haven't had any luck trying to re-write the script. I can't get numbers to reconcile. Not sure if I'm using the correct variables in the script. If you know of anywhere I can get html help let me know.

NTDOCAdministrator
(KiX Master)
2006-09-18 07:22 AM
Re: Generate html report on free space - servers

HTML help as in how to edit/write HTML code, just Google it. Tons of sites.

I've been away from the computer for a few days, just got back tonight.

Hopefully as soon as I catch up to things at work I'll be able to take a look at the code and get it working correctly and then I'll post an update.