Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Space in HardDisk

Reply
Thread Tools Display Modes

Space in HardDisk

 
 
MiguelA
Guest
Posts: n/a

 
      12-23-2009
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

 
Reply With Quote
 
 
 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      12-23-2009


"MiguelA" <> said this in news item
news:84B02BEC-D648-4050-A796-...
> 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 = ""
.To = ""
.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") = ""
.Item (schema & "smtpaccountname") = ""
.Item (schema & "sendpassword") = "SomePassword"
End With
.Configuration.Fields.Update
.Send
End With


 
Reply With Quote
 
MiguelA
Guest
Posts: n/a

 
      12-31-2009
I can not implement all the code!

"Pegasus [MVP]" <> wrote in message
news:...
>
>
> "MiguelA" <> said this in news item
> news:84B02BEC-D648-4050-A796-...
>> 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 = ""
> .To = ""
> .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") = ""
> .Item (schema & "smtpaccountname") = ""
> .Item (schema & "sendpassword") = "SomePassword"
> End With
> .Configuration.Fields.Update
> .Send
> End With
>
>


 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a

 
      12-31-2009



"MiguelA" <> said this in news item
news:86144BCB-29F3-43B4-AF6A-...
> 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.


 
Reply With Quote
 
MiguelA
Guest
Posts: n/a

 
      12-31-2009
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]" <> wrote in message
news:...
>
>
> "MiguelA" <> said this in news item
> news:86144BCB-29F3-43B4-AF6A-...
>> 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.
>
>
>


 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a

 
      12-31-2009
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" <> said this in news item
news:#...
> 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]" <> wrote in message
> news:...
>>
>>
>> "MiguelA" <> said this in news item
>> news:86144BCB-29F3-43B4-AF6A-...
>>> 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.
>>
>>
>>

>

 
Reply With Quote
 
MiguelA
Guest
Posts: n/a

 
      12-31-2009
I will try and tell you something

"Pegasus [MVP]" <> wrote in message
news:...
> 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" <> said this in news item
> news:#...
>> 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]" <> wrote in message
>> news:...
>>>
>>>
>>> "MiguelA" <> said this in news item
>>> news:86144BCB-29F3-43B4-AF6A-...
>>>> 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.
>>>
>>>
>>>

>>


 
Reply With Quote
 
MiguelA
Guest
Posts: n/a

 
      01-08-2010
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,authenticationLev el=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" <> wrote in message
news:eJ$...
>I will try and tell you something
>
> "Pegasus [MVP]" <> wrote in message
> news:...
>> 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" <> said this in news item
>> news:#...
>>> 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]" <> wrote in message
>>> news:...
>>>>
>>>>
>>>> "MiguelA" <> said this in news item
>>>> news:86144BCB-29F3-43B4-AF6A-...
>>>>> 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.
>>>>
>>>>
>>>>
>>>

>


 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a

 
      01-08-2010
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" <> said this in news item
news:E4204C0F-B9A5-4911-AFCD-...
> 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,authenticationLev el=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" <> wrote in message
> news:eJ$...
>>I will try and tell you something
>>
>> "Pegasus [MVP]" <> wrote in message
>> news:...
>>> 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" <> said this in news item
>>> news:#...
>>>> 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]" <> wrote in message
>>>> news:...
>>>>>
>>>>>
>>>>> "MiguelA" <> said this in news item
>>>>> news:86144BCB-29F3-43B4-AF6A-...
>>>>>> 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.
>>>>>
>>>>>
>>>>>
>>>>

>>

>

 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a

 
      01-12-2010
See inline.

"Eric" <> said this in news item
news:afe5bf19-4d9b-41f5-9b34-...
> 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-AFCD-...
>>
>>
>>
>> > 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,authenticationLev el=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$...
>> >>I will try and tell you something

>>
>> >> "Pegasus [MVP]" <n...@microsoft.com> wrote in message
>> >>news:...
>> >>> 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:#...
>> >>>> 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:.. .

>>
>> >>>>> "MiguelA" <ma.camal...@NOSPAMgmail.com> said this in news item
>> >>>>>news:86144BCB-29F3-43B4-AF6A-...
>> >>>>>> 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.

> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows 2003 R2 - Missing Disk Space on System drive zinger-uk Windows Server 12 11-29-2009 12:02 PM
Defrag increases "used space" as reported by command-line defrag - mwhiting001@hotmail.com.NO_SPAM Windows Vista Performance 15 06-19-2009 08:34 PM
Will Vista carve out space for another partition during the setup? JMI Windows Vista Installation 9 02-23-2007 09:37 PM
Will Vista carve out space for another partition during the setup? JMI Windows Vista File Management 9 02-23-2007 09:37 PM
Defrag - Vista vs. XP Dave Nuttall Windows Vista Performance 8 02-11-2007 03:58 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59