You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Get-ChildItem批量检查所有.policy文件夹下的文件是否合规

你可以通过先递归检索所有.policy文件夹、再逐个校验的方式实现需求,参考实现代码如下:

# 定义允许的文件名称列表
$allowedFiles = @('azureDeploy.parameters.json', 'azureDeploy.json')
# 递归检索所有名称为 .policy 的文件夹,替换路径为你需要扫描的根目录
$policyFolders = Get-ChildItem -Path "替换为你的扫描根目录路径" -Directory -Recurse -Filter ".policy"

# 逐个校验每个 .policy 文件夹内的文件
foreach ($folder in $policyFolders) {
    Write-Host "校验路径:$($folder.FullName)"
    $currentFiles = (Get-ChildItem -Path $folder.FullName -File -Recurse).Name
    $currentFiles | Should -BeIn $allowedFiles
}

补充说明:

  • 如果你不需要校验.policy文件夹内子目录的文件,可以删除第二个Get-ChildItem后的-Recurse参数
  • 如果需要明确输出非法文件名称方便排查,可以在foreach循环内追加判断逻辑:
$invalidFiles = $currentFiles | Where-Object { $_ -notin $allowedFiles }
if ($invalidFiles) {
    Write-Host "发现非法文件:$($invalidFiles -join '、')" -ForegroundColor Red
}

内容的提问来源于stack exchange,提问作者Nadia Hansen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 22:06:03