我是 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,并且是本地管理员。
编辑: 经过Richard的建议,我尝试了详细模式(似乎没有效果)。
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 D:\path_A\* -recurse -force
关于powershell - PowerShell 中的权限错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7738571/