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

时间:2016-02-05 14:17:48

标签: powershell powershell-remoting

我正在尝试运行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

1 个答案:

答案 0 :(得分:0)

同意消息' Access被拒绝'是一个你无法访问的死亡赠品。

我会创建一个凭证变量,并确保它是一个拥有远程系统权限的凭证。 $ Creds = Get-Credential 然后将代码更改为以下内容(我添加了-scriptblock和粗体文本

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

相关问题