powershell - New-PSSession - WinRM 无法处理请求
问题描述
我正在尝试使用 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
解决方案
错误消息清楚地表明您想要连接到名为Server
的服务器,而不是连接到名称存储在$Server
变量中的服务器(粗体文本实际上是您尝试连接的服务器的名称):
New-PSSession : [ Server ] 连接到远程服务器服务器失败
如果您尝试连接到名为 example 的服务器,MyServer01.example.com
您将收到如下错误(截断):
PS C:\> New-PSSession -ComputerName "MyServer01.example.com"
New-PSSession : [ MyServer01.example.com ] 连接到远程服务器MyServer01.example.com失败 (...)
即使您声明您尝试执行
$s = New-PSSession -ComputerName $Server
您实际执行(注意缺少美元符号)
$s = New-PSSession -ComputerName Server
以上内容也取自您粘贴的错误消息。我建议先跳过变量并尝试在命令本身中输入服务器路径以验证它是否正常工作:
$s = New-PSSession -ComputerName "MyServer01.example.com"
然后,如果可行,请将路径放入变量中并再次测试。
推荐阅读
- javascript - 如何在Vue多选和预选选项中选择键?Vue
- sql - 按日期过滤问题
- javascript - Gatsby 在页面刷新时丢失/消失的 CSS?
- python - Pandas.dataframe 在解析字典时增加了一行
- javascript - VUE.js | V-bind - 数组和过滤器
- python - python中同名的变量和常量
- java - 如何在 Android 中读取相对路径上的 Json
- python - 使用 .copy() 创建可以在不更改原始字典的情况下进行编辑的字典副本
- angular - 如何在角度的mat日期选择器中设置日期格式
- javascript - 如何在 DynamoDB 中的单个属性上查询(getItems)两个条件(不存在 + 某个值)?