Jump to content

Free Space


techie
 Share

Recommended Posts

I am trying to create a script that looks at a csv file (list of servers) and reports back the (total space-used space-free space-%used-%free) on all the HDD on the lists servers B) and write the info back to a csv file. At the moment I have to manually check 128 servers weekly via terminal services and log the results. So far I have

$nSpaceFree = DriveSpaceFree($sDrv)
$nSpaceTotal = DriveSpaceTotal($sDrv)
$nPct = 100 * $nSpaceFree / $nSpaceTotal
$sOut = $sOut & $sDrv & " (Free=" & StringFormat("%.2fMb",$nSpaceFree) & "; Total=" & StringFormat("%.2fMb",$nSpaceTotal) & ")" & @LF
$sOut = $sOut & StringLeft($sBar, $nPct) & " = " & "(" & StringFormat("%.2f",$nPct) & "%)" & @LF
Any help would be very welcome :o
Link to comment
Share on other sites

you just want to check some pc's?

why don't you use psinfo - don't know where i got it from but you can google it out

it can check all pc's in a domain and store the data to a txt-file if you want

then you should be able to convert it to csv

if i find the prog i'll post the link

found it

http://www.sysinternals.com/Utilities/PsInfo.html

Edited by Nuffilein805
Link to comment
Share on other sites

Thanks for the reply

I have tried PsInfo before it works but brings back other info that is not require like the computer name uptime CPU.

The output needed is something like this

Server Drive Format Total Used Free % Used % Free Volumename

SERVER1 C NTFS 3.91 GB 3.76 GB 145.16 MB 96.37 3.63 Main Drive

SERVER1 D NTFS 33.91 GB 206.09 MB 33.71 GB 0.59 99.41 New Volume

SERVER1 F NTFS 13.01 GB 833.51 MB 12.20 GB 6.26 93.74 New Volume

SERVER2 C NTFS So no

SERVER2 X NTFS So no

SERVER2 Y NTFS So no

Which needs going to a csv file, is it possible.

Edited by techie
Link to comment
Share on other sites

Welcome to the forums!

AutoIt can definitely get that information for any local drives; I don't think it can handle drives over a server. If PsInfo does everything you want except not in a desired format, with a bit of work AutoIt can manipulate the output into a suitable form via its string functions.

Does this sound like something worth doing?

Edit: I reread your initial post. If you're doing things via Terminal Services and if you can get away with placing an AutoIt script on the servers, you could use that script to process each server and send the results back to you.

Edited by LxP
Link to comment
Share on other sites

Thanks for posting reply

This is the info from psinfo

Servername,0 days 4 hours 20 minutes 38 seconds,Microsoft Windows XP, Uniprocessor Free,Professional,5.1,2,2600,XXXXXXXX,XXXX,12/04/2005, 08:25:30,Error readin

g status,6.0000,C:\WINDOWS,1,2.5 GHz,Intel® Celeron® CPU,766 MB,Intel® 722

1 Integrated Graphics Controller, C: Fixed NTFS

74.43 GB 65.61 GB 88.2%, D: Fixed NTFS

7.38 GB 2.73 GB 36.9%, E: Fixed NTFS Apps

10.77 GB 613.23 MB 5.6%, F: Fixed NTFS Images

39.06 GB 18.33 GB 46.9%, G: Removable FAT

249.92 MB 168.52 MB 67.4%, I: CD-ROM

0.0%, J: CD-ROM

0.0%, P: Remote NTFS New Volume 303

.60 GB 149.02 GB 49.1%, Z: Remote NTFS 593.

99 GB 507.59 GB 85.5%

The txt in red is not needed C: Fixed replace with just letter the rest needs formating as shown in last post

Server Drive Format Total Used Free % Used % Free Volumename

SERVER1 C NTFS 3.91 GB 3.76 GB 145.16 MB 96.37 3.63GB Main Drive

According to psinfo it can query a txt file with a list of names...

As for TS I logon to the server and do properties on each drive and write it to a csv file but doing 128 (drives) and an ever increasing server list it's getting a bit time consuming so I could do with scripting this in so way.

Thanks for reading

Edited by techie
Link to comment
Share on other sites

Edit: I reread your initial post. If you're doing things via Terminal Services and if you can get away with placing an AutoIt script on the servers, you could use that script to process each server and send the results back to you.

Yes I can add files/scripts on to the servers - if I have to put a script on each server that runs at a set time/day and each script reports the info back to a csv file that would do the trick B) So the first server/script would run/write to the csv file then 5mins later say the second-server-script could run and append/add to the same file and so no and so forth... Is this possible?

Link to comment
Share on other sites

It's definitely possible, but I'm not convinced that it's the most ideal solution.

You mention that all of the servers can write to a central location. Is it possible for one central location to read (say, a file?) from all of those servers?

If so, you could set up a script on those servers to periodically (and automatically) check the necessary information and keep an updated CSV fragment somewhere accessible.

Following this approach, at the point that you need a consolidated report you can just contact all of the servers for those fragments and combine them into a single file with ease.

In my opinion the ultimate solution would be to query the disk information remotely via one process running on one computer; then AutoIt (and the appropriate tool, perhaps PsInfo?) would only need to be running on that one computer. Is this feasible?

Link to comment
Share on other sites

It's definitely possible, but I'm not convinced that it's the most ideal solution.

You mention that all of the servers can write to a central location. Is it possible for one central location to read (say, a file?) from all of those servers?

If so, you could set up a script on those servers to periodically (and automatically) check the necessary information and keep an updated CSV fragment somewhere accessible.

Following this approach, at the point that you need a consolidated report you can just contact all of the servers for those fragments and combine them into a single file with ease.

In my opinion the ultimate solution would be to query the disk information remotely via one process running on one computer; then AutoIt (and the appropriate tool, perhaps PsInfo?) would only need to be running on that one computer. Is this feasible?

YES B) thats looking like something I am trying to do whether a script calls a file from the servers or the servers writes to a file does not matter as I have permission on the servers and the csv file is store on my system and I upload it to another location on a web server so staff can see the HDD usage on the server within the site.

ultimate solution would be to query the disk information remotely via one process running on one computer; then AutoIt

Link to comment
Share on other sites

If you can find a utility that reports all the necessary information to a command prompt window (or to a file even) then AutoIt can process that information and manipulate and combine it as necessary.

Have you been able to trigger PsInfo to read all of the necessary information from all of the servers? It doesn't matter if it can't be done all in one invocation of PsInfo.

Link to comment
Share on other sites

Thanks for replying

Post 5 Yes LxP post 5 was a report from my system the info in red would not be needed but the rest is what I am look for just the formatting of the info needs sorting. I havn't tried it on the servers just yet till I get it reporting from my system to the file correct, with the right format.

Link to comment
Share on other sites

Well, here's a script that will parse the information from PsInfo for the local system. You need PsInfo.exe to reside in the same folder as the script when you run it in uncompiled form. You also need the beta.

You can compile it for use on the remote computers -- PsInfo.exe will be included within it, so you won't need remote copies of that.

#Include <Constants.au3>
Opt('MustDeclareVars', True)
Opt('RunErrorsFatal', False)

; Location to store CSV output
Local Const $CSV = 'C:\Drives.csv'

; Extract PsInfo to the temporary directory
If Not FileInstall('PsInfo\PsInfo.exe', @TempDir) Then Die('Could not extract PsInfo to a temporary location.')

; Start PsInfo
Local $PID = Run(@TempDir & '\PsInfo.exe -D', '', Default, $STDOUT_CHILD)
If @Error Then
    FileDelete(@TempDir & '\PsInfo.exe')
    Die('Could not start PsInfo.')
EndIf

; Read its complete output
Local $Output = ''
Do
    $Output &= StdOutRead($PID)
Until @Error

; Remove PsInfo from the temporary directory
FileDelete(@TempDir & '\PsInfo.exe')

; Remove the unneeded information (i.e. everything before the column headers)
Local $ColumnsStart = StringInStr($Output, 'Volume Type    ')
If $ColumnsStart = 0 Then Die("Could not find the needed information in PsInfo's output." & @LF & @LF & $Output)
$Output = StringMid($Output, $ColumnsStart)

; Remove the column headers
$Output = StringTrimLeft($Output, StringInStr($Output, @LF))

; Open the CSV output file for writing
Local $CSVHandle = FileOpen($CSV, $FO_OVERWRITE)
If $CSVHandle = -1 Then Die('Could not open ' & $CSV & ' for over/writing.')

; Parse each line
While $Output <> ''
; Read the bits
    Local $Drive = StringStripWS(StringLeft($Output, 6), $STR_STRIPLEADING)
    $Output = StringTrimLeft($Output, 7)
    Local $Type = StringStripWS(StringLeft($Output, 10), $STR_STRIPTRAILING)
    $Output = StringTrimLeft($Output, 11)
    Local $Format = StringStripWS(StringLeft($Output, 10), $STR_STRIPTRAILING)
    $Output = StringTrimLeft($Output, 11)
    Local $Label = StringStripWS(StringLeft($Output, 20), $STR_STRIPTRAILING)
    $Output = StringTrimLeft($Output, 21)
    Local $Size = StringStripWS(StringLeft($Output, 10), $STR_STRIPLEADING)
    $Output = StringTrimLeft($Output, 11)
    Local $FreeSize = StringStripWS(StringLeft($Output, 10), $STR_STRIPLEADING)
    $Output = StringTrimLeft($Output, 11)
    Local $FreePercent = StringStripWS(StringLeft($Output, 5), $STR_STRIPLEADING)
    $Output = StringTrimLeft($Output, 6)
; Infer the used percent from the free percent
    Local $UsedPercent = StringFormat('%.1f', 100 - $FreePercent)
; Remove this line from the output
    $Output = StringTrimLeft($Output, StringInStr($Output, @LF))
; Add this information to the CSV output
    FileWriteLine($CSVHandle, StringFormat('%s,%s,%s,%s,%s,%s,%s,%s', @ComputerName, $Drive, $Format, $Size, $FreeSize, $UsedPercent, $FreePercent, $Label))
WEnd
FileClose($CSVHandle)

Func Die($Msg)
    MsgBox(0x10, 'Error', $Msg)
    Exit
EndFunc
Link to comment
Share on other sites

LxP

Had a good go at it today and the script is coming up with errors and I am lost to the answer

>"C:\Program Files\AutoIt3beta\SciTe\CompileAU3\CompileAU3.exe" /run /prod /ErrorStdOut /in "C:\psinfo\freespace.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams

>Running AU3Check...C:\Program Files\AutoIt3beta\SciTe\Defs\Production\Au3Check\au3check.dat

>AU3Check Ended. No Error(s).

>Running: (3.1.1.0):C:\Program Files\AutoIt3\autoit3.exe "C:\psinfo\freespace.au3"

C:\psinfo\freespace.au3 (2) : ==> Unknown function name.:

Opt('MustDeclareVars', True)

Opt('MustDeclareVars', ^ ERROR

>AutoIT3.exe ended.

>Exit code: 0 Time: 0.730

Could you cast your eye over it please

Link to comment
Share on other sites

How about having a program run on the server that checks it? Maybe setup a scheduled task and then write it to a share..?

I started working on something similar but never finished it. Would this help?

#include <file.au3>
_diskcheck()
Func _diskcheck()
    $var = DriveGetDrive( "all")
    If Not @error Then
        For $i = 1 To $var[0]
            $d_filesys = DriveGetFileSystem($var[$i])
            If $d_filesys = "UDF" Then
            ;do nothing
            ElseIf $d_filesys = "1" Then;no media
            ;do nothing
            ElseIf $d_filesys = "FAT" Then
                $var1 = DriveSpaceFree($var[$i])
                $var1 = $var1 / 1024
                $var1 = Round($var1, 1)
                _FileWriteLog("Space.log", "There is " & $var1 & " GB of Free Space left on disk " & $var[$i] & " Drive is FAT32")
            ElseIf $d_filesys = "NTFS" Then
            ;MsgBox(32,"NTFS",$var[$i])
                $var1 = DriveSpaceFree($var[$i])
                $var1 = $var1 / 1024
                $var1 = Round($var1, 1)
            ;MsgBox(4096, "Free Space on " & $var[$i],"There is " & $var1 & " GB of Free Space Left")
                _FileWriteLog("Space.log", "There is " & $var1 & " GB of Free Space left on disk " & $var[$i] & " Drive is NTFS")
            ElseIf $d_filesys = "CDFS" Then
            ;do nothing
            EndIf
        Next
    EndIf
EndFunc  ;==>_diskcheck

Func _WriteDiskInfo()
;do Write Task here.
$server = ""
$file = "File.csv"
$path = "\\" & $server & "\folder\" & $file
EndFunc
Link to comment
Share on other sites

this uses beta and can be run remotely, just replace @ComputerName with the computer you want the info from.

$info = _DriveInfo(@ComputerName)
If IsArray($info) Then
    For $x = 1 To $info[0]
        MsgBox(0,"drive info",$info[$x])
    Next
EndIf


Func _DriveInfo($s_Machine = "localhost")
    Local Const $wbemFlagReturnImmediately = 0x10
    Local Const $wbemFlagForwardOnly = 0x20
    Local $colItems = "", $objWMIService, $objItem, $SpaceTotal, $FreeSpace, $item
    Local $DriveType[7] = ["Unknown", "No Root Directory", "Removable Disk", "Local Disk", "Network Drive", "Compact Disc", "RAM Disk"]
    
    Local $Output = ""
    $objWMIService = ObjGet("winmgmts:\\" & $s_Machine & "\root\CIMV2")
    If @error Then
        MsgBox(16, "_DriveInfo", "ObjGet Error: winmgmts")
        Return
    EndIf
    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_LogicalDisk WHERE DriveType = 3", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If @error Then
        MsgBox(16, "_DriveInfo", "ExecQuery Error: SELECT * FROM Win32_LogicalDisk")
        Return
    EndIf
    If IsObj($colItems) Then
        For $objItem In $colItems
            $SpaceTotal = ($objItem.Size / 1024) / 1024
            If ($SpaceTotal > 1024) Then
                $SpaceTotal = Round($SpaceTotal / 1024, 0) & " GB"
            ElseIf ($SpaceTotal > 0) Then
                $SpaceTotal = Round($SpaceTotal, 0) & " MB"
            EndIf
            $FreeSpace = ($objItem.FreeSpace / 1024) / 1024
            If ($FreeSpace > 1024) Then
                $FreeSpace = Round($FreeSpace / 1024, 0) & " GB"
            ElseIf ($FreeSpace > 0) Then
                $FreeSpace = Round($FreeSpace, 0) & " MB"
            EndIf
            $item = "Drive: " & $objItem.Caption & "|" & "Type: " & $DriveType[$objItem.DriveType] & "|" & "Total Size: " & $SpaceTotal & "|" & "Free Space: " & $FreeSpace & "|" & "File System: " & $objItem.FileSystem
        Next
        Return StringSplit($item,"|")
    EndIf
EndFunc  ;==>_DriveInfo
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...