powershell - PowerShell 中的权限错误

标签 powershell

我是 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/

相关文章:

powershell - 使用 select-string 在同一文档中查找 2 个字符串

powershell - 使用 Tee 从另一个 shell 运行 PowerShell

powershell - CMD:如何在一行中查找Windows中总内存的数值?

c# - 调用AzureInformationProtection Powershell命令时出现C#Microsoft InformationProtection解密错误

PowerShell - 为什么我的脚本使用默认类字段创建对象?

git - Powershell 中的 "Git Log"命令 - 无法终止进程

windows - 如何在 Powershell 和 nano 下保存 git commit 消息? (Ctrl+O 无效)

powershell - 启用IISNET45时出错

security - 使用 PowerShell V2 的 Send-MailMessage 通过 Gmail 发送邮件

c# - 在 TransactionScope 中调用 Runspace.Open() 会更改 Transaction.Current 并抛出异常