远程在多台服务器上执行 powershell 脚本
Execute a powershell script on multiple servers remotely
我写了一个 powershell
脚本,它可以卸载程序并在我的服务器上安装该程序的更新版本(更新程序)。现在我想创建另一个脚本 运行 服务器上的上述脚本。考虑到我必须通过使用 IP、用户名和密码连接到我的服务器,并且不能使用域。
这怎么可能?
Powershell 版本为 4
我试过这段代码来简单地获取日期:
$User = "administrator"
$PWord = ConvertTo-SecureString -String "Password1234" -AsPlainText -Force
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User, $PWord
$session = New-PSSession -ComputerName '10.60.60.100' -Credential $Credential
Invoke-Command -Session $session -ScriptBlock {Get-Date}
我收到了这个错误:
New-PSSession : [10.60.60.100] Connecting to remote server 10.60.60.100 failed with the following error message : The WinRM client cannot process the request. If the authentication scheme is different from Kerberos, or if the client computer is not joined to a domain, then HTTPS transport must be used or the destination machine must be added to the TrustedHosts configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts list might not be authenticated. You can get more information about that by running the following command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic.
这是因为您不是运行来自受信任主机的命令,或者因为远程计算机 wsman 服务配置不正确。我将从 运行 以下命令开始在远程机器上配置 wsman:
wsman quickconfig
如果这不能解决问题,那么您需要将您的计算机添加到远程计算机的受信任主机。您可以通过 运行 执行以下操作:
winrm s winrm/config/client '@{TrustedHosts="RemoteComputer"}'
我写了一个 powershell
脚本,它可以卸载程序并在我的服务器上安装该程序的更新版本(更新程序)。现在我想创建另一个脚本 运行 服务器上的上述脚本。考虑到我必须通过使用 IP、用户名和密码连接到我的服务器,并且不能使用域。
这怎么可能?
Powershell 版本为 4
我试过这段代码来简单地获取日期:
$User = "administrator"
$PWord = ConvertTo-SecureString -String "Password1234" -AsPlainText -Force
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User, $PWord
$session = New-PSSession -ComputerName '10.60.60.100' -Credential $Credential
Invoke-Command -Session $session -ScriptBlock {Get-Date}
我收到了这个错误:
New-PSSession : [10.60.60.100] Connecting to remote server 10.60.60.100 failed with the following error message : The WinRM client cannot process the request. If the authentication scheme is different from Kerberos, or if the client computer is not joined to a domain, then HTTPS transport must be used or the destination machine must be added to the TrustedHosts configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts list might not be authenticated. You can get more information about that by running the following command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic.
这是因为您不是运行来自受信任主机的命令,或者因为远程计算机 wsman 服务配置不正确。我将从 运行 以下命令开始在远程机器上配置 wsman:
wsman quickconfig
如果这不能解决问题,那么您需要将您的计算机添加到远程计算机的受信任主机。您可以通过 运行 执行以下操作:
winrm s winrm/config/client '@{TrustedHosts="RemoteComputer"}'