无法运行我自己的 Powershell Cmdlet,因为对文件夹"Templates"访问被拒绝?



我刚开始使用Powershell,我遇到了一个奇怪的错误,我找不到我们的朋友谷歌先生的详细信息。

在你问之前,是的,我肯定是以管理员的身份运行Powershell的。

我创建了一个简单的Cmdlet,它统计当前目录中指定扩展名的文件。

我可以构建并运行installutil fine。

当我调用Get-PSSnapin-Registered时,我可以看到管理单元,并且我可以使用add-PSSnapin 添加它

但当我运行cmdlet时,我会得到以下错误:

PS C:workEnterprise> Get-PSSnapin -Registered

Name        : FileCountCmdlet
PSVersion   : 2.0
Description : Returns a file count

PS C:work> Add-PSSnapin FileCountCmdlet
PS C:work> Get-FileCount
Get-FileCount : Access to the path 'C:Users{My-User-Name}Templates' is denied.
At line:1 char:14
+ Get-FileCount <<<<
    + CategoryInfo          : NotSpecified: (:) [Get-FileCount], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,FileCount.FileCountCmdlet

如有任何想法或帮助,我们将不胜感激!

听起来你可能遇到了这个链接所描述的:

连接点

http://www.svrops.com/svrops/articles/jpoints.htm

如果是这样,则需要更新cmdlet以跳过这些连接点。

相关内容