我是PowerShell的新手。当试图编写一个简单的脚本来删除一个文件夹的内容,然后用从不同文件夹复制的文件填充它时,我总是会得到一个PermissionDenied
错误。PowerShell中的权限错误
详情:
+ 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\
就是这样。删除项似乎扔在每个文件。
您是否确实有权删除错误中记录的文件** save.gif **和** file.txt **? –
是的,当控制台无法工作时,我所做的第一件事就是试图手动删除它们。 (我也在开场白中说过,但也许我有点含糊,对不起) – ver
你能提供脚本吗? – JPBlanc