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

Le Thien Lam 21 Reputation points
2020-08-06T02:30:12.21+00:00

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
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,628 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Rich Matheisen 47,766 Reputation points
    2020-08-06T19:30:25.81+00:00

    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.

    1 person found this answer helpful.
    0 comments No comments

  2. Le Thien Lam 21 Reputation points
    2020-08-06T03:53:04.197+00:00

    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!

    0 comments No comments

  3. Young Yang (Shanghai Wicresoft Co,.Ltd.) 661 Reputation points
    2020-08-20T01:48:58.433+00:00

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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.