PowerShell 中的权限错误 [英] Permission errors in PowerShell

查看:78
本文介绍了PowerShell 中的权限错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 PowerShell 的新手.在尝试编写一个简单的脚本来删除文件夹的内容,然后用从不同文件夹复制的文件填充它时,我总是收到 PermissionDenied 错误.

I am new to PowerShell. When trying to write a simple script that deletes the contents of a folder and then fills it with files copied from a different folder, I always get a PermissionDenied error.

详情:

+ 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 并且是本地管理员.

Where is the problem? I am able to manipulate both folders through Explorer. The error occurs both when running from a script file and from shell (using Windows PowerShell ISE). The ISE process runs under my account. I'm running Windows 7 Professional and am a local administrator.

经过理查德的建议,我尝试了详细模式(似乎没有效果).

After Richard's suggestion, I tried the verbose mode (which seemed to have no effect).

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}

我觉得那里没什么用(但还是感谢您的提示).

I don't see anything of much use there (but thanks for the tips anyway).

编辑 2:好的,这是脚本源:

remove-item D:\path_A\* -recurse
copy-item D:\path_B\* D:\path_A\

就是这样.remove-item 似乎会抛出每个文件.

That's it. The remove-item seems to throw at every file.

推荐答案

是否启用了 UAC?如果是这样,请尝试以管理员"身份运行 PowerShell 会话.看起来您确实没有删除对象的权限.

Is UAC enabled? If so try running your PowerShell session as 'Administrator'. It really looks like you don't have permission to delete the objects.

我们在我工作的地方制定了非常严格的安全政策,不熟悉 UAC 的用户总是受到伤害.

We have very restrictive security policies where I work and users not familiar with UAC get burned all the time.

这篇关于PowerShell 中的权限错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆