运行脚本但由于某种原因它给我一个错误,指出“文件夹不存在”,除非我已经导航到该位置。
例如我在 c:\folder1 中使用 PS 控制台运行脚本 我将脚本指向 c:\folder1 并且它可以工作并执行我需要的操作
如果我从 c:\ 运行脚本并告诉脚本检查 c:\folder1 它然后告诉我它无法访问文件夹 1 中的目录,因为它们不存在但文件夹 1 中有明确的内容>
$User = read-host 'Input name'
$exportfile = Read-Host 'Save location of export'
$directory = read-host 'Directory to check'
$folders = gci -Directory $directory
foreach ($path in $folders)
{
if ($path.PSIsContainer -eq $false)
{
continue
}
$permission = (Get-Acl $path).Access | ?{$_.IdentityReference -match $User} | Select IdentityReference,FileSystemRights
If ($permission){
$permission | % {Write-Host " $($_.IdentityReference) has '$($_.FileSystemRights)' rights on folder $path"}
$write = % {"$user $($_.IdentityReference) has '$($permission.FileSystemRights)' rights on folder $($path)"} | Out-File -FilePath $exportfile -NoClobber -Append
}
Else {
continue
}
}