小编Kev*_*in_的帖子

Get-ChildItem -force在"我的文档"文件夹和其他联结点上报告"拒绝访问"

我有一个我写的脚本替换文件.我将params传递给它以获取文件的名称和要搜索的基本位置.工人线是:

$SubLocations = Get-ChildItem -Path $Startlocation -Recurse -include $Filename -Force  | 
                Where { $_.FullName.ToUpper().contains($Filter.ToUpper())}
Run Code Online (Sandbox Code Playgroud)

我将$ Startlocation设置为"C:\ Users",但是,当我试图通过其他用户文件夹进行递归时,我被拒绝访问.我是机器上的完全管理员,我已经尝试过运行PowerShell作为管理员.我可以通过Windows资源管理器访问所有文件,没有任何问题.任何的想法?

Get-ChildItem : Access to the path 'C:\Users\jepa227\Documents\My Music' is denied.
At C:\Users\krla226\Google Drive\Documents\PowerShell\Replace-File.ps1:35 char:46
+ $SubLocations = Get-ChildItem <<<<  -Path $Startlocation -Recurse -    include $Filename -Force | 
    + CategoryInfo          : PermissionDenied: (C:\Users\jepa227\Documents\My     Music:String) [Get-ChildItem], Una 
   uthorizedAccessException
+ FullyQualifiedErrorId :  DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
Run Code Online (Sandbox Code Playgroud)

UPDATE

虽然我无法通过GCI工作,但我能够使用WMI来解决我的问题.对于有兴趣的人:

$SubLocations = Get-WmiObject -Class cim_datafile -Filter "fileName = '$filename' AND Extension = '$extension'" | 
                            Where { $_.Name.ToUpper().contains($Filter.ToUpper()) }
Run Code Online (Sandbox Code Playgroud)

powershell acl access-denied

11
推荐指数
2
解决办法
2万
查看次数

标签 统计

access-denied ×1

acl ×1

powershell ×1