![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||