尝试检查特定路径中的文件夹是使用PowerShell共享还是不共享。如果共享,将返回true值

时间:2017-06-15 08:07:16

标签: powershell

我的剧本

[ { _id: '59385ef6d2d80c00d9bdef97', count: 1000, user: [_id:"59385ef6d2d80c00d9bdef97",name:"XX"] } ]

请帮我解决脚本

1 个答案:

答案 0 :(得分:1)

避免重复查询wmi,反转逻辑:

$TestPath = 'd:\test path'
$AllShares = Get-WmiObject -Class Win32_Share
Get-ChildItem $TestPath -Directory <#-Recurse<##> -Force -ErrorAction SilentlyContinue | 
    ForEach-Object{
        $vari = $_.FullName -in $AllShares.Path
        if (<#$true -or <##> $vari) { '{0,-6}{1}' -f $vari, $_.FullName }
}

(可选)删除阻止评论开始标记<#(您可以保留<##>)。