Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Space in HardDisk

5 views
Skip to first unread message

MiguelA

unread,
Dec 23, 2009, 4:59:16 PM12/23/09
to
Hi!!!

I need a script that monitors the hard drives of servers and when you reach
a minimum space constraints, I send an email warning.
How can I do?, Exists already implemented?

THANKS

Pegasus [MVP]

unread,
Dec 23, 2009, 5:19:37 PM12/23/09
to

"MiguelA" <ma.ca...@NOSPAMgmail.com> said this in news item
news:84B02BEC-D648-4050...@microsoft.com...

You could use this script as a basis when working out the amount of free
disk space:

aDType = Split("Unknown Removable Fixed Network CDROM RAMDISK")
Set oFSO = CreateObject("Scripting.FileSystemObject")
LF = Chr(10)

sLine = "Drive Type State Label F/S Size Free
Serial"
WScript.Echo sLine
WScript.Echo String(Len(sLine)+2, "-")
For Each oDrive In oFSO.Drives
D = oDrive.DriveType
if D > UBound(aDType) then D = 0
sLine = oDrive.Path & " " & aDType(D)

If oDrive.IsReady Then
sLine = Append(sLine, "ready", 18, False)
If oDrive.DriveType = 3 Then
sLine = Append(sLine, Left(oDrive.ShareName, 13), 29, False)
Else
sLine = Append(sLine, Left(oDrive.VolumeName, 13), 29, False)
End If

sLine = Append(sLine, oDrive.FileSystem, 44, False)
sLine = Append(sLine, Int(oDrive.TotalSize/1000000), 51, True)
sLine = Append(sLine, Int(oDrive.FreeSpace/1000000), 59, True)
sLine = Append(sLine, Hex(oDrive.SerialNumber), 67, False)
Else
sLine = Append(sLine, "not ready", 18, False)
End If
WScript.Echo sLine
Next

Function Append(L, S, n, numerical)
if n < Len(L) + 2 then n = 2 Else n = n - Len(L)
If numerical Then
Append = L & Left(Space(60), n + 6 - Len(S)) & S
Else
Append = L & Left(Space(60), n) & S
End If
End Function
===================================
And here is something to send a message:

const cdoBasic=1
schema = "http://schemas.microsoft.com/cdo/configuration/"
Set objEmail = CreateObject("CDO.Message")
With objEmail
.From = "Ja...@company.com"
.To = "J...@company.com"
.Subject = "Test Mail"
.Textbody = "The quick brown fox " & Chr(10) & "jumps over the lazy dog"
.AddAttachment "d:\Testfile.txt"
With .Configuration.Fields
.Item (schema & "sendusing") = 2
.Item (schema & "smtpserver") = "mail.company.com"
.Item (schema & "smtpserverport") = 25
.Item (schema & "smtpauthenticate") = cdoBasic
.Item (schema & "sendusername") = "Ja...@company.com"
.Item (schema & "smtpaccountname") = "Ja...@company.com"
.Item (schema & "sendpassword") = "SomePassword"
End With
.Configuration.Fields.Update
.Send
End With

MiguelA

unread,
Dec 31, 2009, 10:23:39 AM12/31/09
to
I can not implement all the code!

"Pegasus [MVP]" <ne...@microsoft.com> wrote in message
news:OvHfG4Bh...@TK2MSFTNGP04.phx.gbl...

Pegasus [MVP]

unread,
Dec 31, 2009, 10:31:03 AM12/31/09
to


"MiguelA" <ma.ca...@NOSPAMgmail.com> said this in news item

news:86144BCB-29F3-43B4...@microsoft.com...


> I can not implement all the code!

The idea is for you to grab the parts that are relevant for you. Feel free
to ask if certain details are unclear.

MiguelA

unread,
Dec 31, 2009, 10:36:34 AM12/31/09
to
I do not understand is as if it detects that there is little space to run
the email sending.
If a server has multiple disks, it detects all?.

"Pegasus [MVP]" <ne...@microsoft.com> wrote in message

news:OJ4oH5ii...@TK2MSFTNGP04.phx.gbl...

Pegasus [MVP]

unread,
Dec 31, 2009, 10:50:58 AM12/31/09
to
When you examine and run the script then you will see several things:
a) The script will inspect *all* drive letters.
b) The property oDrive.Path shows the drive letter (e.g. D:)
c) The property oDrive.AvailableSpace shows the amount of free space.

You now need to compare oDrive.AvailableSpace against whatever limit you
wish to set, then invoke the EMail module if your free space drops below the
set limit.


"MiguelA" <ma.ca...@NOSPAMgmail.com> said this in news item

news:#9fXH8ii...@TK2MSFTNGP06.phx.gbl...

MiguelA

unread,
Dec 31, 2009, 10:57:23 AM12/31/09
to
I will try and tell you something

"Pegasus [MVP]" <ne...@microsoft.com> wrote in message

news:e4ixPEji...@TK2MSFTNGP02.phx.gbl...

MiguelA

unread,
Jan 8, 2010, 3:27:55 AM1/8/10
to
I have this, but as email command??

Option Explicit

Dim strComputer, objWMIService, colMonitoredDisks, objDiskChange
Dim i, strMessage
Const LOCAL_HARD_DISK = 3

strComputer = "West204"
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" & strComputer
& "\root\cimv2")
Set colMonitoredDisks = objWMIService.ExecNotificationQuery ("SELECT * FROM
__instancemodificationevent WITHIN 30 WHERE " & "TargetInstance ISA
'Win32_LogicalDisk'")
i = 0
Do While i = 0
Set objDiskChange = colMonitoredDisks.NextEvent
If objDiskChange.TargetInstance.DriveType = LOCAL_HARD_DISK Then
If objDiskChange.TargetInstance.Size < 100000000 Then
strMessage = "Hard disk " & objDiskChange.TargetInstance.Name
& " on computer " & strComputer & " is below 100,000,000 bytes."
End If
End If
Loop

"MiguelA" <ma.ca...@NOSPAMgmail.com> wrote in message
news:eJ$ivHjiK...@TK2MSFTNGP04.phx.gbl...

Pegasus [MVP]

unread,
Jan 8, 2010, 4:52:40 AM1/8/10
to
I gave you an EMail function in my reply of two weeks ago. Did you use the
function? If something is not clear then please say exactly what it is.

Note also that while WMI is a wonderful thing, it can place a heavy load on
the CPU. I recommend that you check your CPU loading before finalising this
project.

"MiguelA" <ma.ca...@NOSPAMgmail.com> said this in news item

news:E4204C0F-B9A5-4911...@microsoft.com...

Eric

unread,
Jan 12, 2010, 10:11:51 AM1/12/10
to
On Jan 8, 4:52 am, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> I gave you an EMail function in my reply of two weeks ago. Did you use the
> function? If something is not clear then please say exactly what it is.
>
> Note also that while WMI is a wonderful thing, it can place a heavy load on
> the CPU. I recommend that you check your CPU loading before finalising this
> project.
>
> "MiguelA" <ma.camal...@NOSPAMgmail.com> said this in news itemnews:E4204C0F-B9A5-4911...@microsoft.com...

>
>
>
> > I have this, but as email command??
>
> > Option Explicit
>
> > Dim strComputer, objWMIService, colMonitoredDisks, objDiskChange
> > Dim i, strMessage
> > Const LOCAL_HARD_DISK = 3
>
> > strComputer = "West204"
> > Set objWMIService = GetObject("winmgmts:" &
> > "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\"  &
> > strComputer & "\root\cimv2")
> > Set colMonitoredDisks = objWMIService.ExecNotificationQuery  ("SELECT *
> > FROM __instancemodificationevent WITHIN 30 WHERE "  & "TargetInstance ISA
> > 'Win32_LogicalDisk'")
> > i = 0
> > Do While i = 0
> >    Set objDiskChange = colMonitoredDisks.NextEvent
> >    If objDiskChange.TargetInstance.DriveType = LOCAL_HARD_DISK Then
> >        If objDiskChange.TargetInstance.Size < 100000000 Then
> >            strMessage = "Hard disk "  & objDiskChange.TargetInstance.Name
> > & " on computer " & strComputer & " is below 100,000,000 bytes."
> >          End If
> >    End If
> > Loop
>
> > "MiguelA" <ma.camal...@NOSPAMgmail.com> wrote in message

> >news:eJ$ivHjiK...@TK2MSFTNGP04.phx.gbl...
> >>I will try and tell you something
>
> >> "Pegasus [MVP]" <n...@microsoft.com> wrote in message

> >>news:e4ixPEji...@TK2MSFTNGP02.phx.gbl...
> >>> When you examine and run the script then you will see several things:
> >>> a) The script will inspect *all* drive letters.
> >>> b) The property oDrive.Path shows the drive letter (e.g. D:)
> >>> c) The property oDrive.AvailableSpace shows the amount of free space.
>
> >>> You now need to compare oDrive.AvailableSpace against whatever limit you
> >>> wish to set, then invoke the EMail module if your free space drops below
> >>> the set limit.
>
> >>> "MiguelA" <ma.camal...@NOSPAMgmail.com> said this in news item

> >>>news:#9fXH8ii...@TK2MSFTNGP06.phx.gbl...
> >>>> I do not understand is as if it detects that there is little space to
> >>>> run the email sending.
> >>>> If a server has multiple disks, it detects all?.
>
> >>>> "Pegasus [MVP]" <n...@microsoft.com> wrote in message
> >>>>news:OJ4oH5ii...@TK2MSFTNGP04.phx.gbl...
>
> >>>>> "MiguelA" <ma.camal...@NOSPAMgmail.com> said this in news item

> >>>>>news:86144BCB-29F3-43B4...@microsoft.com...
> >>>>>> I can not implement all the code!
>
> >>>>> The idea is for you to grab the parts that are relevant for you. Feel
> >>>>> free to ask if certain details are unclear.- Hide quoted text -
>
> - Show quoted text -

Am I correct that your script in this thread is designed to run
locally on the server?
Is there a way to write a script that can get drive and directory size
information for a server, running on a client pc with network admin
credentials?
From what I can find on the FSO, it only works on the local pc or
mapped drives.
I have a working script which connects to the servers and gets drive
space info from Win32_DiskDrive. Now I want more details, to show
which folders are using the most space, without having the folders
marked as shared.
This would seem simple if I ran it locally on the server but I want to
be able to run it from my client pc and I want it to connect to get
info from multiple servers.

Pegasus [MVP]

unread,
Jan 12, 2010, 10:19:33 AM1/12/10
to
See inline.

"Eric" <edou...@blockhouse.com> said this in news item
news:afe5bf19-4d9b-41f5...@k22g2000vbp.googlegroups.com...

*** Yes.

> Is there a way to write a script that can get drive and directory size
> information for a server, running on a client pc with network admin
> credentials?

*** Yes, WMI is one method, psexec.exe another.

> From what I can find on the FSO, it only works on the local pc or
> mapped drives.

*** Correct.

> I have a working script which connects to the servers and gets drive
> space info from Win32_DiskDrive. Now I want more details, to show
> which folders are using the most space, without having the folders
> marked as shared.
> This would seem simple if I ran it locally on the server but I want to
> be able to run it from my client pc and I want it to connect to get
> info from multiple servers.

*** For good performance I would launch psexec.exe from a batch
*** file on the server, to address each client PC in turn.

Eric

unread,
Jan 12, 2010, 2:25:51 PM1/12/10
to
On Jan 12, 10:19 am, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> See inline.
>
> "Eric" <edoug...@blockhouse.com> said this in news itemnews:afe5bf19-4d9b-41f5...@k22g2000vbp.googlegroups.com...
> *** file on the server, to address each client PC in turn.- Hide quoted text -

>
> - Show quoted text -

So you're saying the only way to get directory size information for
another PC for all folders, not just shared folders, is to run a local
FSO script using PsTools (http://technet.microsoft.com/en-us/
sysinternals/bb897553.aspx)?

ekrengel

unread,
Jan 12, 2010, 4:31:12 PM1/12/10
to
On Jan 12, 10:19 am, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> See inline.
>
> "Eric" <edoug...@blockhouse.com> said this in news itemnews:afe5bf19-4d9b-41f5...@k22g2000vbp.googlegroups.com...

How were you planning to show which folders were using the most space,
locally? Do you have a script for this locally?

Pegasus [MVP]

unread,
Jan 12, 2010, 4:39:33 PM1/12/10
to

"Eric" <edou...@blockhouse.com> said this in news item
news:63b31a85-0957-429b...@m11g2000vbo.googlegroups.com...

*** No. I wrote "WMI is one method, psexec.exe another". You should also
look at the OP's script - he uses WMI.

Pegasus [MVP]

unread,
Jan 12, 2010, 4:38:10 PM1/12/10
to

"ekrengel" <erickr...@gmail.com> said this in news item
news:0a7ac89e-0ff6-4969...@3g2000vbp.googlegroups.com...

Yes, I wrote a script for this some time ago. It's a console script and most
people prefer a pretty GUI such as these:
DriveUse:
http://members.ozemail.com.au/~nulifetv/freezip/freeware/index.html
Bullet Proof Folder sizes: http://www.foldersizes.com/

Eric

unread,
Jan 13, 2010, 1:23:35 PM1/13/10
to
On Jan 12, 4:39 pm, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> "Eric" <edoug...@blockhouse.com> said this in news itemnews:63b31a85-0957-429b...@m11g2000vbo.googlegroups.com...
> look at the OP's script - he uses WMI.- Hide quoted text -

>
> - Show quoted text -

That WMI script is just getting the hard disk space used/available
info. I want that broken down by folder, possibly by file. Can WMI
get the folder details?

I don't really care who it's displayed. I can put my results in a
msgbox locally or write them to a text file either locally or on the
server, anywhere is fine. I just want a script I can run on my local
PC which can access all drives of multiple servers (without having to
share them to map for local access) and tell me what is using the most
space. I can run this script with network admin credentials if
necessary.

Pegasus [MVP]

unread,
Jan 13, 2010, 2:36:48 PM1/13/10
to

"Eric" <edou...@blockhouse.com> said this in news item
news:554734a5-f0bc-4370...@k22g2000vbp.googlegroups.com...

Based on the link below, you could do something like this:

sDrive = "D:\"


Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oRoot = oFSO.GetFolder(sDrive)

For Each oFolder In oRoot.SubFolders
On Error Resume Next
iSize = oFSO.GetFolder(oFolder.Path).Size
If Err.number = 0 Then
WScript.Echo Right(Space(14) & iSize, 14), oFolder.Path
Else
WScript.Echo "(Inaccessible)", oFolder.Path
End If
On Error Goto 0
Next

http://blogs.technet.com/heyscriptingguy/archive/2004/11/18/can-i-use-a-script-to-determine-the-size-of-a-folder-on-a-remote-computer.aspx

Eric

unread,
Jan 13, 2010, 2:58:48 PM1/13/10
to
On Jan 13, 2:36 pm, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> "Eric" <edoug...@blockhouse.com> said this in news itemnews:554734a5-f0bc-4370...@k22g2000vbp.googlegroups.com...
> http://blogs.technet.com/heyscriptingguy/archive/2004/11/18/can-i-use...- Hide quoted text -

>
> - Show quoted text -

Thanks! Your script sample here looks like it only works for the
local PC, but at least one of the ideas in that link should work for a
remote (server) PC. Hopefully the simpler ideas work, otherwise I'll
have to write the last resort option, to write a separate script that
gets folder info for the local machine, then copy that script to a
shared folder on the server and run a command to remote execute it
locally to get the non-shared folder info, then remove the script from
the server.

Pegasus [MVP]

unread,
Jan 13, 2010, 3:58:27 PM1/13/10
to

"Eric" <edou...@blockhouse.com> said this in news item
news:498fe6ed-2ba0-4c26...@37g2000vbn.googlegroups.com...

As I mentioned before in this thread, you can invoke psexec.exe for each
machine in order to invoke my script locally, e.g. like so:

@echo off
for /F %%a in (c:\PCs.lst) do (
psexec.exe \\%%a -u Administrator -p xxx \\Server\Tools\Script.bat %%a
)

The file \\Server\Tools\Script.bat would look like this:
@echo off
cscript //nologo c:\tools\Foldersize.vbs > c:\FolderSizes\%1.txt

c:\PCs.lst is a list of all NetBIOS names that you must compile
c:\tools\Foldersize.vbs is your VB Script
c:\FolderSizes is the result folder

All files and folders are kept centrally on your server for ease of
maintenance.

0 new messages