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.
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
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
"+@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 , "
Server
"+@CRLF) $x = WriteLine( 3 , "
Used
"+@CRLF) $x = WriteLine( 3 , "
"+@CRLF) $x = WriteLine( 3 , "
Avail-Space
"+@CRLF) $x = WriteLine( 3 , "
"+@CRLF) $=Close (3)
EndFunction ;************************************************* Function html($server,$drive,$percentfree,$rest,$free)
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
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<>""
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.
Then to make your file write faster you can change your WriteLine to something like this (untested in working code)
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.
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.
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
"+@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' : (
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
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.
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.
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.
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.
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.