【发布时间】:2011-10-12 10:22:23
【问题描述】:
我是 PowerShell 新手。当尝试编写一个简单的脚本来删除文件夹的内容,然后用从不同文件夹复制的文件填充它时,我总是收到PermissionDenied 错误。
详情:
+ remove-item <<<< D:\path\* -recurse
+ CategoryInfo : PermissionDenied: (save.gif:FileInfo) [Remove-Item], IOException
+ FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
问题出在哪里?我能够通过资源管理器操作这两个文件夹。 从脚本文件和 shell(使用 Windows PowerShell ISE)运行时都会出现该错误。 ISE 进程在我的帐户下运行。 我正在运行 Windows 7 Professional 并且是本地管理员。
编辑: 在理查德的建议下,我尝试了详细模式(似乎没有效果)。
PS Z:\> $error[0] | fl * -force
PSMessageDetails :
Exception : System.IO.IOException: Not Enough permission to perform operation.
TargetObject : D:\path\file.txt
CategoryInfo : PermissionDenied: (D:\path\file.txt:FileInfo) [Remove-Item], IOException
FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
ErrorDetails : Cannot remove item D:\path\file.txt: Not Enough permission to perform operation.
InvocationInfo : System.Management.Automation.InvocationInfo
PipelineIterationInfo : {0, 1}
我没有看到任何有用的东西(但无论如何感谢您的提示)。
编辑 2: 好的,下面是脚本来源:
remove-item D:\path_A\* -recurse
copy-item D:\path_B\* D:\path_A\
就是这样。 remove-item 似乎会扔到每个文件中。
【问题讨论】:
-
您是否真的有权删除错误中记录的文件 save.gif 和 file.txt?
-
是的,当控制台不工作时,我做的第一件事就是尝试手动删除它们。 (我在开场白中也说过,但也许我有点含糊。对此感到抱歉。)
-
能否提供脚本本身?
-
是否启用了 UAC?如果是这样,请尝试以“管理员”身份运行 PowerShell 会话。看起来您确实没有删除对象的权限。您可以发布目录的 ACL 吗?
-
使用
-Exclude开关遇到了一个有趣的问题,导致同样的访问被拒绝问题。为了解决问题,我将其重写为管道 Get-Item | Where-对象。归根结底,-Exclude是个古怪的人……
标签: powershell