question

LeThienLam-3020 avatar image
0 Votes"
LeThienLam-3020 asked YoungYang-MSFT answered

How to delete files by file size=85,000kb with PowerShell script!

Hi Everyone!
I have a folder containing a lot of files = 85,000kb
Please help me, script with Powershell is delete all file=85,000kb.
Thank!

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LeThienLam-3020 avatar image
0 Votes"
LeThienLam-3020 answered

Hi everyone!
I have script delete files:

$limit = 30KB
$path = "F:\Test"

Delete files with size=30KB:

Get-ChildItem -Path $path -Recurse -File | Where-Object { $_.Length -gt $limit } | Remove-Item | Out-GridView

Please view script is OK?
Thank!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
1 Vote"
RichMatheisen-8856 answered

Why not verify the results of the script yourself????

 Get-ChildItem -Path $path -Recurse -File |
     Where-Object { $_.Length -gt $limit } |
         Select-Object -First 10 |
             Remove-Item -WhatIf:$true

Nothing will be deleted and you can check the output to see if it's removing files that aren't what you expect. You can add a -Skip parameter, too (and/or a -Last parameter) to verify a different set of files from the results.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YoungYang-MSFT avatar image
0 Votes"
YoungYang-MSFT answered

Hi, given that this post has been quiet for a while, this is a quick question and answer. Has your question been solved? If so, please mark it as an answer so that users with the same question can find and get help.
:)

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.