【发布时间】:2019-01-11 06:25:04
【问题描述】:
我正在尝试使用 PowerShell 脚本在远程服务器上列出 IIS 中的所有网站。以下是我尝试连接到服务器的方式:
$s = New-PSSession -ComputerName $Server
但是当我运行脚本时出现以下错误:
New-PSSession : [Server] 连接到远程服务器服务器失败 以下错误消息:WinRM 无法处理该请求。以下错误 使用 Kerberos 身份验证时发生:找不到计算机服务器。 验证计算机是否存在于网络上,并且提供的名称是 拼写正确。有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。 在 C:\AppServers\Application.ps1:8 char:8 + $s = New-PSSession -ComputerName 服务器 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException + FullyQualifiedErrorId : NetworkPathNotFound,PSSessionOpenFailed服务器已启用接收远程请求。
更新:
以下是我尝试运行的完整功能:
function audit-servers {
if (Test-path "ApplicationsOnTheServer.txt") {Remove-Item "ApplicationsOnTheServer.txt"}
if (Test-Path "ServersList.txt") {
foreach ($server in Get-Content .\ServersList.txt) {
"Application Server : $server`n" | out-file -FilePath "ApplicationsOnTheServer.txt" -Append
"Applications list:" | out-file -FilePath "ApplicationsOnTheServer.txt" -Append
$s = New-PSSession -ComputerName $server -Credential domainabc\myname
Invoke-Command -Session $s -ScriptBlock {Import-Module WebAdministration;Get-iissite} | out-file -FilePath "ApplicationsOnTheServer.txt" -Append
}
} else {
"ServersList.txt file is missing"
break;
}
"`nAll Done!`n"}
ServersList.txt 有 atstappvmabc.tsteag.com
【问题讨论】:
-
尝试将
Credential参数与域用户一起传递给New-PSSession。传递凭据(即使基本上使用同一用户)可能会解决 Kerberos 问题。 -
错误消息明确指出您将
Server而不是$Server传递给-ComputerName,这是不正确的,除非您的服务器名称实际上是Server。如果更正后您仍然收到错误,它将与您在问题中粘贴的内容不同。 -
我尝试了凭据参数并尝试了域名以及没有成功。
标签: powershell