Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Query disk free space....

Closed Thread
 
Thread Tools Display Modes
Old 05-13-2008   #1 (permalink)
tke402
Guest
 
Posts: n/a

Query disk free space....

Hi,

I am a complete newbie to PShell. Anyway, is there a command that I can use
to query the free space of a disk by percentage and email a distribution list
if it below 10%?

Thanks,

TKE402
 
Old 05-13-2008   #2 (permalink)
Marco Shaw [MVP]
Guest
 
Posts: n/a

Re: Query disk free space....

tke402 wrote:
Quote:

> Hi,
>
> I am a complete newbie to PShell. Anyway, is there a command that I can use
> to query the free space of a disk by percentage and email a distribution list
> if it below 10%?
>
> Thanks,
>
> TKE402
Just to be clear, there isn't a "command" to do this, there's a script
that could be written though.

-You need to query remote computers also?
-Just a single email address or a collection?

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
 
Old 05-13-2008   #3 (permalink)
tke402
Guest
 
Posts: n/a

Re: Query disk free space....

Quering remote servers would be helpful.

The email would be to a distribution list. i.e. ITDept@xxxxxx

"Marco Shaw [MVP]" wrote:
Quote:

> tke402 wrote:
Quote:

> > Hi,
> >
> > I am a complete newbie to PShell. Anyway, is there a command that I can use
> > to query the free space of a disk by percentage and email a distribution list
> > if it below 10%?
> >
> > Thanks,
> >
> > TKE402
>
> Just to be clear, there isn't a "command" to do this, there's a script
> that could be written though.
>
> -You need to query remote computers also?
> -Just a single email address or a collection?
>
> Marco
>
> --
> Microsoft MVP - Windows PowerShell
> http://www.microsoft.com/mvp
>
> PowerGadgets MVP
> http://www.powergadgets.com/mvp
>
> Blog:
> http://marcoshaw.blogspot.com
>
 
Old 05-13-2008   #4 (permalink)
Shay Levi
Guest
 
Posts: n/a

Re: Query disk free space....


Hi TKE402,

You can query remote server disks using get-wmiObject cmdlet:

# replace <computerName> with the remote server name or ip
# replace <smtpServer> with the smtp server name or ip



$disks = get-wmiObject win32_logicaldisk -filter "DriveType=3" -computerName
<computerName> | where { (([long]$_.freespace/[long]$_.size)*100) -lt 10
} | select systemName, DeviceID

if($disks) {
$smtp = new-object system.net.mail.smtpClient(<smtpServer>)
$mail = new-object System.Net.Mail.MailMessage
$mail.from = "me@xxxxxx"
$mail.to.add("ITDept@xxxxxx")
$mail.subject = "Low disk space"
$mail.body = $disks
$smtp.send($mail)
}

---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Quering remote servers would be helpful.
>
> The email would be to a distribution list. i.e. ITDept@xxxxxx
>
> "Marco Shaw [MVP]" wrote:
>
Quote:

>> tke402 wrote:
>>
Quote:

>>> Hi,
>>>
>>> I am a complete newbie to PShell. Anyway, is there a command that I
>>> can use to query the free space of a disk by percentage and email a
>>> distribution list if it below 10%?
>>>
>>> Thanks,
>>>
>>> TKE402
>>>
>> Just to be clear, there isn't a "command" to do this, there's a
>> script that could be written though.
>>
>> -You need to query remote computers also?
>> -Just a single email address or a collection?
>> Marco
>>
>> --
>> Microsoft MVP - Windows PowerShell
>> http://www.microsoft.com/mvp
>> PowerGadgets MVP
>> http://www.powergadgets.com/mvp
>> Blog:
>> http://marcoshaw.blogspot.com

 
Old 05-13-2008   #5 (permalink)
tke402
Guest
 
Posts: n/a

Re: Query disk free space....

Maybe there is an error with my word wrap or the way I'm cutting and pasting.
I am receivnig error that may be pertaining to syntax. Just to make sure, are
the two references to computer name correct?

-computerName
<computerName>

or do you just mean to have it there once?

Thanks,

TKE402

"Shay Levi" wrote:
Quote:

>
> Hi TKE402,
>
> You can query remote server disks using get-wmiObject cmdlet:
>
> # replace <computerName> with the remote server name or ip
> # replace <smtpServer> with the smtp server name or ip
>
>
>
> $disks = get-wmiObject win32_logicaldisk -filter "DriveType=3" -computerName
> <computerName> | where { (([long]$_.freespace/[long]$_.size)*100) -lt 10
> } | select systemName, DeviceID
>
> if($disks) {
> $smtp = new-object system.net.mail.smtpClient(<smtpServer>)
> $mail = new-object System.Net.Mail.MailMessage
> $mail.from = "me@xxxxxx"
> $mail.to.add("ITDept@xxxxxx")
> $mail.subject = "Low disk space"
> $mail.body = $disks
> $smtp.send($mail)
> }
>
> ---
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

> > Quering remote servers would be helpful.
> >
> > The email would be to a distribution list. i.e. ITDept@xxxxxx
> >
> > "Marco Shaw [MVP]" wrote:
> >
Quote:

> >> tke402 wrote:
> >>
> >>> Hi,
> >>>
> >>> I am a complete newbie to PShell. Anyway, is there a command that I
> >>> can use to query the free space of a disk by percentage and email a
> >>> distribution list if it below 10%?
> >>>
> >>> Thanks,
> >>>
> >>> TKE402
> >>>
> >> Just to be clear, there isn't a "command" to do this, there's a
> >> script that could be written though.
> >>
> >> -You need to query remote computers also?
> >> -Just a single email address or a collection?
> >> Marco
> >>
> >> --
> >> Microsoft MVP - Windows PowerShell
> >> http://www.microsoft.com/mvp
> >> PowerGadgets MVP
> >> http://www.powergadgets.com/mvp
> >> Blog:
> >> http://marcoshaw.blogspot.com
>
>
>
 
Old 05-13-2008   #6 (permalink)
Marco Shaw [MVP]
Guest
 
Posts: n/a

Re: Query disk free space....

tke402 wrote:
Quote:

> Maybe there is an error with my word wrap or the way I'm cutting and pasting.
> I am receivnig error that may be pertaining to syntax. Just to make sure, are
> the two references to computer name correct?
>
> -computerName
> <computerName>
>
> or do you just mean to have it there once?
What Shay meant here is that this part:

-computerName <computerName>

You should be inserting whatever computer you want to query, like so,
for example:

-computerName server1.domain

Marco


--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
 
 
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query shared folder free space David Kriz PowerShell 24 06-07-2008 04:12 PM
Misreported Used/Free Disk Space Shade_C Vista General 3 04-17-2008 07:11 AM
RE: SP1 CREATES Free Disk Space! Jason Vista General 1 03-25-2008 09:01 AM
Out of disk space error at installations, though 100 Gb free space Evagoud Vista General 5 11-04-2007 02:48 AM
disk free space anomaly dave4503 Vista performance & maintenance 2 06-15-2006 05:54 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

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