尝试枚举远程计算机上的驱动器时出现“访问被拒绝”错误

问题描述:

我试图运行PowerShell命令来获取所有远程服务器的所有驱动器的总磁盘空间。当我运行命令时,我得到下面的错误。我有一个具有服务器名称的文本文件,我也确认WinRM已配置并正在运行。尝试枚举远程计算机上的驱动器时出现“访问被拒绝”错误

$Servers = Get-Content "C:\users\anorris\desktop\DR\servers1.txt" 
foreach ($s in $Servers) { 
    Invoke-Command -ComputerName $s {Get-PSDrive} 
} 

错误:

[ahv-a2acortst02] Connecting to remote server failed with the following error 
message : Access is denied. 
For more information, see the about_Remote_Troubleshooting Help topic. 
     + CategoryInfo   : OpenError: (:) [], PSRemotingTransportException 
     + FullyQualifiedErrorId : PSSessionStateBroken
+0

该错误信息是直线前进。你不这样做,或该进程没有,有权访问驱动器。您是否查看过? –

+0

该错误特别提到了['about_Remote_Troubleshooting'](https://technet.microsoft.com/zh-cn/library/hh84 7850.aspx)帮助主题。你看过那个吗?你的发现是什么? –

一致认为消息“访问被拒绝”是你没有访问权限的破绽。

我会创建一个凭证变量并确保它是一个拥有远程系统权限的凭证。 $ Creds = GET-凭证 然后更改您的代码如下(我加了-ScriptBlock和黑体字

$服务器=获取内容的“C:\用户\ anorris \桌面\ DR \ servers1.txt “ 的foreach($ S $中的服务器){ 调用命令-ComputerName $ S -ScriptBlock {GET-PSDrive来} -Credential $ creds }