首页 文章

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

提问于
浏览
-6

我正在尝试运行PowerShell命令以获取所有远程服务器的所有驱动器的总磁盘空间 . 当我运行命令时,我收到以下错误 . 我有一个文本文件,其中包含服务器的名称,我还确认WinRM已配置并正在运行 .

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

Error:

[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

    同意“访问被拒绝”这一消息是您无法访问的死亡赠品 .

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

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

相关问题