Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Help creating powershell CMNDLET to find all large files and folde

Reply
 
Old 03-05-2007   #1 (permalink)
JMinahan


 
 

Help creating powershell CMNDLET to find all large files and folde

Help creating powershell CMNDLET to find all large files and folders on a
system. Before I begin, I know C++, Java, and batch file programming, but
Powershell is brand new to me.

I have a server that I want to automate the following three items on:

-Find top 20 largest directories
-Find top 20 largest files
-Find all media (MP3, OOG, MPG, ect) that is not supposed to be there.

I know have come up with a couple commands to do this, I am stuck with the
two needs. Here is what I came up with:

#1. [Finds media]

Get-ChildItem C:\ -recurse -include *.mp3,*.wma,*.wmv,*.mov,*.mpg,*.ogg|
Sort-Object length -descending

#2. [Finds all files puts largest first]

Get-ChildItem C:\ -recurse -include | Sort-Object length -descending

So with the given information, here is what I need:

#1. How do I run these two commands and output it to a file? I used to use a
">" in dos to write screen to file, and then use copy t.txt + s.txt to
combine them.

#2. These commands get ALL files but I only want to show the TOP 20 largest.
Is there a way to do this with the sort option? The Get-EventLog (system
-newest 5 | Sort-Object eventid) made it easy and gave us the "newest 5"
method.

#3. I want to email the results to an email alias (jason@cje.com for
expample). I usually use a "start run mailto:jason@cje.com" in my DOS batch
scripts.

HELP! I really want to get this going for work. I love Powershell and it's
robustness but I am still learning it.

Thanks for any help you can provide.

My System SpecsSystem Spec
Old 03-05-2007   #2 (permalink)
Sung M Kim


 
 

Re: Help creating powershell CMNDLET to find all large files and folde

Comments in-line.

On Mar 5, 9:25 am, JMinahan <JMina...@discussions.microsoft.com>
wrote:
> #1. How do I run these two commands and output it to a file? I used to use a
> ">" in dos to write screen to file, and then use copy t.txt + s.txt to
> combine them.

Run each command and "append" output using "out-file" using "-Append"
switch.

Get-ChildItem C:\ -recurse -include
*.mp3,*.wma,*.wmv,*.mov,*.mpg,*.ogg | sort length -descending | out-
file -Append output.txt
Get-ChildItem C:\ -recurse -include | Sort-Object length -descending |
out-file -Append output.txt


> #2. These commands get ALL files but I only want to show the TOP 20 largest.
> Is there a way to do this with the sort option? The Get-EventLog (system
> -newest 5 | Sort-Object eventid) made it easy and gave us the "newest 5"
> method.

You can retrieve top 20 records using "select-object" cmdlet's "-
First" parameter
Get-ChildItem C:\ -recurse -include | Sort-Object length -descending |
select -first 20

> #3. I want to email the results to an email alias (j...@cje.com for
> expample). I usually use a "start run mailto:j...@cje.com" in my DOS batch
> scripts.


PowerShell CX(Community Extension) Project on http://www.CodePlex.com/PowerShellCX
has a cmdlet called "Send-SmtpMail" which you can use to send emails
of the output.


I am sure that others have much better ways to accomplish the above
tasks that others can come up with surely
In the meantime, hope the above can help you to get started a bit.

My System SpecsSystem Spec
Old 03-05-2007   #3 (permalink)
JMinahan


 
 

Re: Help creating powershell CMNDLET to find all large files and f

Thanks so much

"Sung M Kim" wrote:

> Comments in-line.
>
> On Mar 5, 9:25 am, JMinahan <JMina...@discussions.microsoft.com>
> wrote:
> > #1. How do I run these two commands and output it to a file? I used to use a
> > ">" in dos to write screen to file, and then use copy t.txt + s.txt to
> > combine them.

> Run each command and "append" output using "out-file" using "-Append"
> switch.
>
> Get-ChildItem C:\ -recurse -include
> *.mp3,*.wma,*.wmv,*.mov,*.mpg,*.ogg | sort length -descending | out-
> file -Append output.txt
> Get-ChildItem C:\ -recurse -include | Sort-Object length -descending |
> out-file -Append output.txt
>
>
> > #2. These commands get ALL files but I only want to show the TOP 20 largest.
> > Is there a way to do this with the sort option? The Get-EventLog (system
> > -newest 5 | Sort-Object eventid) made it easy and gave us the "newest 5"
> > method.

> You can retrieve top 20 records using "select-object" cmdlet's "-
> First" parameter
> Get-ChildItem C:\ -recurse -include | Sort-Object length -descending |
> select -first 20
>
> > #3. I want to email the results to an email alias (j...@cje.com for
> > expample). I usually use a "start run mailto:j...@cje.com" in my DOS batch
> > scripts.

>
> PowerShell CX(Community Extension) Project on http://www.CodePlex.com/PowerShellCX
> has a cmdlet called "Send-SmtpMail" which you can use to send emails
> of the output.
>
>
> I am sure that others have much better ways to accomplish the above
> tasks that others can come up with surely
> In the meantime, hope the above can help you to get started a bit.
>
>

My System SpecsSystem Spec
Old 03-05-2007   #4 (permalink)
Marcel J. Ortiz [MSFT]


 
 

Re: Help creating powershell CMNDLET to find all large files and f

There is no way to tell sort that you only want the top 20 items so it will
collect all the items and then sort them. You can probably improve
performance by writing your own filter which only holds 20 items at a time.


"JMinahan" <JMinahan@discussions.microsoft.com> wrote in message
news:ECAF4CB0-6AD9-4E35-90A7-630452CA47EC@microsoft.com...
> Thanks so much
>
> "Sung M Kim" wrote:
>
>> Comments in-line.
>>
>> On Mar 5, 9:25 am, JMinahan <JMina...@discussions.microsoft.com>
>> wrote:
>> > #1. How do I run these two commands and output it to a file? I used to
>> > use a
>> > ">" in dos to write screen to file, and then use copy t.txt + s.txt to
>> > combine them.

>> Run each command and "append" output using "out-file" using "-Append"
>> switch.
>>
>> Get-ChildItem C:\ -recurse -include
>> *.mp3,*.wma,*.wmv,*.mov,*.mpg,*.ogg | sort length -descending | out-
>> file -Append output.txt
>> Get-ChildItem C:\ -recurse -include | Sort-Object length -descending |
>> out-file -Append output.txt
>>
>>
>> > #2. These commands get ALL files but I only want to show the TOP 20
>> > largest.
>> > Is there a way to do this with the sort option? The Get-EventLog
>> > (system
>> > -newest 5 | Sort-Object eventid) made it easy and gave us the "newest
>> > 5"
>> > method.

>> You can retrieve top 20 records using "select-object" cmdlet's "-
>> First" parameter
>> Get-ChildItem C:\ -recurse -include | Sort-Object length -descending |
>> select -first 20
>>
>> > #3. I want to email the results to an email alias (j...@cje.com for
>> > expample). I usually use a "start run mailto:j...@cje.com" in my DOS
>> > batch
>> > scripts.

>>
>> PowerShell CX(Community Extension) Project on
>> http://www.CodePlex.com/PowerShellCX
>> has a cmdlet called "Send-SmtpMail" which you can use to send emails
>> of the output.
>>
>>
>> I am sure that others have much better ways to accomplish the above
>> tasks that others can come up with surely
>> In the meantime, hope the above can help you to get started a bit.
>>
>>


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
is there a way to process large files in powershell? PowerShell
How to download large files using powershell (.zip,.tar) PowerShell
unable to copy compressed files from other computers' shared folde Vista networking & sharing
Vista Problem - "Could not find this item" error on viewable folde Vista General
how to find large files Vista file management


Vista Forums 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 Ltd

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