C盘满windows10下面c盘爆红,满了如何正确找到该文件夹。

以下是powershell 下面的代码(代码在图最下方)。

1.记得要用管理员模式启动powershell

2.代码记得保存为psl 为后缀的文件

3.运行时候要免签名按照我下面的命令格式运行就可以。

powershell -ExecutionPolicy Bypass -File .\findsize.ps1 -RootPath "C:\Users\Administrator"-SizeThresholdMB 500

#给小白门解释一下 

1.findsize.ps1是代码保存的文件,你可以任意起名。.\就不用解释了吧,路径而已,你在不同的路径需要更改。

2.-RootPath "C:\Users\Administrator" 这里引号里面是你要查找文件夹大小的路径。

3.-SizeThresholdMB 500 ,这里是查找大于500的文件夹,并且举例出来。500这个参数是你按照你需要随便填写。

以下是代码段:

# 2024_5_16_By_ZS执行命令的方法 powershell -ExecutionPolicy Bypass -File .\findsize.ps1 -RootPath "C:\Users\Administrator"-SizeThresholdMB 500

param (
    [Parameter(Mandatory=$true)]
    [string]$RootPath,
    
    [Parameter(Mandatory=$false)]
    [int]$SizeThresholdMB = 1000
)

function GetFolderSize {
    param (
        [string]$folderPath
    )
    try {
        $items = Get-ChildItem -LiteralPath $folderPath -Recurse -File -Force -ErrorAction Stop | Measure-Object -Property Length -Sum
        return [math]::Round($items.Sum / 1MB, 2)
    } catch {
        return -1
    }
}

function FindLargeFolders {
    param (
        [string]$rootPath,
        [int]$sizeThresholdMB
    )
    Get-ChildItem -LiteralPath $rootPath -Directory -Recurse -Force -ErrorAction SilentlyContinue | ForEach-Object {
        try {
            $folderPath = $_.FullName
            $folderSize = GetFolderSize -folderPath $folderPath
            if ($folderSize -gt $sizeThresholdMB) {
                Write-Output "$folderPath - $folderSize MB"
            }
        } catch {
            # 忽略错误
        }
    }
}

# 调用函数开始执行
try {
    FindLargeFolders -rootPath $RootPath -sizeThresholdMB $SizeThresholdMB
} catch {
    Write-Error "脚本执行过程中发生错误: $_"
}

祝大家好运!

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值