Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 检查是否存在具有特定大小的文件夹_Powershell - Fatal编程技术网

Powershell 检查是否存在具有特定大小的文件夹

Powershell 检查是否存在具有特定大小的文件夹,powershell,Powershell,从执行的getchilditem命令中,我想检查是否存在大小大于1gb的文件夹。由于特定原因,gci命令不能直接与一起执行,其中对象{$psiscontainer},必须在执行该gci后进行过滤。编辑重新排列的代码一点 这应该会有所帮助,我使用了您的想法,即使用脚本.FileSystemObject,并修改了函数以返回所有大于提供的$minsize function Get-FolderBySize { param ( [string]$path, [I

从执行的
getchilditem
命令中,我想检查是否存在大小大于1gb的文件夹。由于特定原因,gci命令不能直接与
一起执行,其中对象{$psiscontainer}
,必须在执行该gci后进行过滤。

编辑重新排列的代码一点

这应该会有所帮助,我使用了您的想法,即使用
脚本.FileSystemObject
,并修改了函数以返回所有大于提供的
$minsize

function Get-FolderBySize {  
   param (
        [string]$path,
        [Int32]$minSize # in GB
    )

    $folders = gci -Path $Path -Recurse -Force -ErrorAction SilentlyContinue | ? {$_.PSisContainer -eq $true}
    $FileSystemObject = New-Object -ComObject  Scripting.FileSystemObject   

    foreach ($folder in $folders)
    { 
        $size = $FileSystemObject.GetFolder($folder.FullName).Size / 1GB

        if ($size -ge $minSize)
        {
            $size = "{0:N}" -f $size
            Write-host "Folder $($folder.Fullname) has a size of $size GB" 
            $folder
        }
    }
}

您需要对文件夹中包含的所有文件以及所有子文件夹进行递归计算,然后才能确定文件夹的大小。Windows没有提供直接获取完整大小的方法。除了@Robbert注释,请检查此链接:我已经有了扫描所有文件夹的功能。我的问题是如何检查是否存在大小为1gb的文件夹。我更新了我的问题。