Page 1 of 4 1234>
Topic Options
#135036 - 2005-03-08 09:19 PM Generate html report on free space - servers
Styles Offline
Fresh Scripter

Registered: 2005-02-22
Posts: 12
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.
Top
#135037 - 2005-03-08 09:35 PM Re: Generate html report on free space - servers
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1341
Loc: NL
something like this..




It's NTDoc's script

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




Edited by Co (2005-03-08 09:39 PM)
_________________________
Co


Top
#135038 - 2005-03-08 09:44 PM Re: Generate html report on free space - servers
Styles Offline
Fresh Scripter

Registered: 2005-02-22
Posts: 12
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.
Top
#135039 - 2005-03-08 09:54 PM Re: Generate html report on free space - servers
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1341
Loc: NL
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...
_________________________
Co


Top
#135040 - 2005-03-08 10:28 PM Re: Generate html report on free space - servers
Styles Offline
Fresh Scripter

Registered: 2005-02-22
Posts: 12
Agreed. No harm meant in my reply. I've been looking over the code.
Top
#135041 - 2005-03-08 11:16 PM Re: Generate html report on free space - servers
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1341
Loc: NL
OK...
_________________________
Co


Top
#135042 - 2005-03-11 06:21 PM Re: Generate html report on free space - servers
Styles Offline
Fresh Scripter

Registered: 2005-02-22
Posts: 12
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.

Top
#135043 - 2005-03-11 06:33 PM Re: Generate html report on free space - servers
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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.

Top
#135044 - 2005-03-11 08:34 PM Re: Generate html report on free space - servers
Styles Offline
Fresh Scripter

Registered: 2005-02-22
Posts: 12
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.
Top
#135045 - 2005-03-11 09:27 PM Re: Generate html report on free space - servers
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
After the line:
$WMI = GetObject("winmgmts:\\" + $server + "\root\cimv2")
what does @Error return?

You sure that WMI is installed?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135046 - 2005-03-12 02:33 PM Re: Generate html report on free space - servers
Styles Offline
Fresh Scripter

Registered: 2005-02-22
Posts: 12
That returns a 0 in the output file. Yes WMI in installed on the servers.
Top
#135047 - 2005-03-12 02:35 PM Re: Generate html report on free space - servers
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Might be an issue with un-mached quotes or other syntax problems. Comment out all lines, then re-enable line-by-line and test.
_________________________
There are two types of vessels, submarines and targets.

Top
#135048 - 2005-03-12 02:48 PM Re: Generate html report on free space - servers
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135049 - 2005-03-12 02:50 PM Re: Generate html report on free space - servers
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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")

Top
#135050 - 2005-03-12 02:54 PM Re: Generate html report on free space - servers
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135051 - 2005-03-12 02:55 PM Re: Generate html report on free space - servers
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
OH, and another thought... do any of your servernames have hyphens in them?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135052 - 2005-03-12 02:57 PM Re: Generate html report on free space - servers
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
ja, or it could be a credentials problem. get your local machine working first.
Top
#135053 - 2005-03-12 03:07 PM Re: Generate html report on free space - servers
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
When reading from a list, you also have to be real careful not to get any trailing spaces in there.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135054 - 2005-03-12 03:10 PM Re: Generate html report on free space - servers
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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) ...
Top
#135055 - 2005-03-14 01:49 AM Re: Generate html report on free space - servers
Styles Offline
Fresh Scripter

Registered: 2005-02-22
Posts: 12
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.

Top
Page 1 of 4 1234>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 369 anonymous users online.
Newest Members
rrosell, PatrickPinto, Raoul, Timothy, Jojo67
17877 Registered Users

Generated in 0.086 seconds in which 0.03 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org