Discussion:
Space in HardDisk
(too old to reply)
MiguelA
2009-12-23 21:59:16 UTC
Permalink
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]
2009-12-23 22:19:37 UTC
Permalink
Post by MiguelA
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
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 = "***@company.com"
.To = "***@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") = "***@company.com"
.Item (schema & "smtpaccountname") = "***@company.com"
.Item (schema & "sendpassword") = "SomePassword"
End With
.Configuration.Fields.Update
.Send
End With
MiguelA
2009-12-31 15:23:39 UTC
Permalink
I can not implement all the code!
Post by Pegasus [MVP]
Post by MiguelA
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
You could use this script as a basis when working out the amount of free
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
===================================
const cdoBasic=1
schema = "http://schemas.microsoft.com/cdo/configuration/"
Set objEmail = CreateObject("CDO.Message")
With objEmail
.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 & "sendpassword") = "SomePassword"
End With
.Configuration.Fields.Update
.Send
End With
Pegasus [MVP]
2009-12-31 15:31:03 UTC
Permalink
Post by MiguelA
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
2009-12-31 15:36:34 UTC
Permalink
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?.
Post by Pegasus [MVP]
Post by MiguelA
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.
Pegasus [MVP]
2009-12-31 15:50:58 UTC
Permalink
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.
Post by MiguelA
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?.
Post by Pegasus [MVP]
Post by MiguelA
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
2009-12-31 15:57:23 UTC
Permalink
I will try and tell you something
Post by Pegasus [MVP]
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.
Post by MiguelA
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?.
Post by Pegasus [MVP]
Post by MiguelA
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
2010-01-08 08:27:55 UTC
Permalink
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
Post by MiguelA
I will try and tell you something
Post by Pegasus [MVP]
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.
Post by MiguelA
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?.
Post by Pegasus [MVP]
Post by MiguelA
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.
Pegasus [MVP]
2010-01-08 09:52:40 UTC
Permalink
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.
Post by MiguelA
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
Post by MiguelA
I will try and tell you something
Post by Pegasus [MVP]
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.
Post by MiguelA
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?.
Post by Pegasus [MVP]
Post by MiguelA
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.
Eric
2010-01-12 15:11:51 UTC
Permalink
Post by Pegasus [MVP]
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.
Post by MiguelA
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
Post by MiguelA
I will try and tell you something
Post by Pegasus [MVP]
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.
Post by MiguelA
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?.
Post by Pegasus [MVP]
Post by MiguelA
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]
2010-01-12 15:19:33 UTC
Permalink
See inline.
Post by Eric
Post by Pegasus [MVP]
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.
Post by MiguelA
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
Post by MiguelA
I will try and tell you something
Post by Pegasus [MVP]
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.
Post by MiguelA
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?.
Post by Pegasus [MVP]
Post by MiguelA
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?
*** Yes.
Post by Eric
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.
Post by Eric
From what I can find on the FSO, it only works on the local pc or
mapped drives.
*** Correct.
Post by Eric
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
2010-01-12 19:25:51 UTC
Permalink
Post by Pegasus [MVP]
See inline.
Post by Eric
Post by Pegasus [MVP]
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.
Post by MiguelA
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
Post by MiguelA
I will try and tell you something
Post by Pegasus [MVP]
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.
Post by MiguelA
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?.
Post by Pegasus [MVP]
Post by MiguelA
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?
*** Yes.
Post by Eric
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.
Post by Eric
From what I can find on the FSO, it only works on the local pc or
mapped drives.
*** Correct.
Post by Eric
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.- 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)?
Pegasus [MVP]
2010-01-12 21:39:33 UTC
Permalink
Post by Eric
Post by Pegasus [MVP]
See inline.
Post by Eric
Post by Pegasus [MVP]
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.
Post by MiguelA
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
Post by MiguelA
I will try and tell you something
Post by Pegasus [MVP]
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.
Post by MiguelA
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?.
Post by Pegasus [MVP]
Post by MiguelA
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?
*** Yes.
Post by Eric
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.
Post by Eric
From what I can find on the FSO, it only works on the local pc or
mapped drives.
*** Correct.
Post by Eric
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.- 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)?
*** No. I wrote "WMI is one method, psexec.exe another". You should also
look at the OP's script - he uses WMI.
Eric
2010-01-13 18:23:35 UTC
Permalink
Post by Pegasus [MVP]
Post by Eric
Post by Pegasus [MVP]
See inline.
Post by Eric
Post by Pegasus [MVP]
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.
Post by MiguelA
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
Post by MiguelA
I will try and tell you something
Post by Pegasus [MVP]
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.
Post by MiguelA
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?.
Post by Pegasus [MVP]
Post by MiguelA
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?
*** Yes.
Post by Eric
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.
Post by Eric
From what I can find on the FSO, it only works on the local pc or
mapped drives.
*** Correct.
Post by Eric
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.- 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)?
*** No. I wrote "WMI is one method, psexec.exe another". You should also
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]
2010-01-13 19:36:48 UTC
Permalink
Post by Eric
Post by Pegasus [MVP]
Post by Eric
Post by Pegasus [MVP]
See inline.
Post by Eric
Post by Pegasus [MVP]
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.
Post by MiguelA
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
Post by MiguelA
I will try and tell you something
Post by Pegasus [MVP]
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.
Post by MiguelA
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?.
Post by Pegasus [MVP]
Post by MiguelA
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?
*** Yes.
Post by Eric
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.
Post by Eric
From what I can find on the FSO, it only works on the local pc or
mapped drives.
*** Correct.
Post by Eric
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.- 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)?
*** No. I wrote "WMI is one method, psexec.exe another". You should also
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.
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
2010-01-13 19:58:48 UTC
Permalink
Post by Pegasus [MVP]
Post by Eric
Post by Pegasus [MVP]
Post by Eric
Post by Pegasus [MVP]
See inline.
Post by Eric
Post by Pegasus [MVP]
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.
Post by MiguelA
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
Post by MiguelA
I will try and tell you something
Post by Pegasus [MVP]
When you examine and run the script then you will see several
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.
Post by MiguelA
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?.
Post by Pegasus [MVP]
Post by MiguelA
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?
*** Yes.
Post by Eric
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.
Post by Eric
From what I can find on the FSO, it only works on the local pc or
mapped drives.
*** Correct.
Post by Eric
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.- 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)?
*** No. I wrote "WMI is one method, psexec.exe another". You should also
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.
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...- 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]
2010-01-13 20:58:27 UTC
Permalink
Post by Eric
Post by Pegasus [MVP]
Post by Eric
Post by Pegasus [MVP]
Post by Eric
Post by Pegasus [MVP]
See inline.
Post by Eric
Post by Pegasus [MVP]
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.
Post by MiguelA
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
Post by MiguelA
I will try and tell you something
Post by Pegasus [MVP]
When you examine and run the script then you will see several
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.
Post by MiguelA
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?.
Post by Pegasus [MVP]
Post by MiguelA
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?
*** Yes.
Post by Eric
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.
Post by Eric
From what I can find on the FSO, it only works on the local pc or
mapped drives.
*** Correct.
Post by Eric
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.- 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)?
*** No. I wrote "WMI is one method, psexec.exe another". You should also
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.
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...-
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.
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.

ekrengel
2010-01-12 21:31:12 UTC
Permalink
Post by Pegasus [MVP]
See inline.
Post by Eric
Post by Pegasus [MVP]
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.
Post by MiguelA
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
Post by MiguelA
I will try and tell you something
Post by Pegasus [MVP]
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.
Post by MiguelA
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?.
Post by Pegasus [MVP]
Post by MiguelA
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?
*** Yes.
Post by Eric
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.
Post by Eric
From what I can find on the FSO, it only works on the local pc or
mapped drives.
*** Correct.
Post by Eric
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.
How were you planning to show which folders were using the most space,
locally? Do you have a script for this locally?
Pegasus [MVP]
2010-01-12 21:38:10 UTC
Permalink
Post by ekrengel
Post by Pegasus [MVP]
See inline.
Post by Eric
Post by Pegasus [MVP]
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.
Post by MiguelA
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
Post by MiguelA
I will try and tell you something
Post by Pegasus [MVP]
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.
Post by MiguelA
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?.
Post by Pegasus [MVP]
Post by MiguelA
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?
*** Yes.
Post by Eric
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.
Post by Eric
From what I can find on the FSO, it only works on the local pc or
mapped drives.
*** Correct.
Post by Eric
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.
How were you planning to show which folders were using the most space,
locally? Do you have a script for this locally?
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/
Loading...