首页 文章

VSTS Remote Powershell任务抛出错误

提问于
浏览
0

我在VSTS中创建一个构建定义,它将构建Windows服务并将Windows服务部署到特定服务器 .

我能够将所有必需的Windows服务文件复制到服务器中 . 我使用powershell脚本来安装和启动这些Windows服务 . 我已在服务器中安装了PowerShell脚本 . 我的上一个VSTS任务Remote Powershell任务正在抛出以下内容

[错误]连接到远程服务器失败,并显示以下错误消息:WinRM无法完成操作 . 验证指定的计算机名称是否有效,计算机是否可通过网络访问,以及是否启用了WinRM服务的防火墙例外,并允许从此计算机进行访问 . 默认情况下,公共配置文件的WinRM防火墙例外限制对同一本地子网内的远程计算机的访问 . 有关详细信息,请参阅about_Remote_Troubleshooting帮助主题 .

Powershel脚本代码:

$serviceName = "Service"
$displayName = "Service name"            
$sourceLocation = "C:\temp\Service\bin\Release\*"
$destinationLocation = "C:\TestService\"
$binaryName = $destinationLocation + "Service1.exe"
$serviceName = "Service1"
$serviceDef = Get-Service -Name $serviceName -ErrorAction SilentlyContinue

If ($serviceDef -eq $null)
{
   New-Item $destinationLocation -ItemType directory 
   Copy-Item $sourceLocation $destinationLocation -Force
   New-Service -Name $serviceName -StartupType Automatic -DisplayName $displayName -BinaryPathName $binaryName
}
else
{
  # has already been installed
  if($serviceDef.Status -eq "Running")
  {
    Stop-Service -Name $serviceName        
  }
  Copy-Item $sourceLocation $destinationLocation -Force
}
Start-Service -Name $serviceName


$serviceName = "Service2"
$displayName = "Service2"            
$sourceLocation = "C:\temp\Service2\bin\Release\*"
$destinationLocation = "C:\Service2\"
$binaryName = $destinationLocation + "Service2.exe"
$serviceName = "Service2"
$serviceDef = Get-Service -Name $serviceName -ErrorAction SilentlyContinue

If ($serviceDef -eq $null)
{
   New-Item $destinationLocation -ItemType directory 
   Copy-Item $sourceLocation $destinationLocation -Force
   New-Service -Name $serviceName -StartupType Automatic -DisplayName $displayName -BinaryPathName $binaryName
}
else
{
  # has already been installed
  if($serviceDef.Status -eq "Running")
  {
    Stop-Service -Name $serviceName        
  }
  Copy-Item $sourceLocation $destinationLocation -Force
}
Start-Service -Name $serviceName

1 回答

  • 0

    根据错误消息,它应该是WinRM问题,您需要在特定服务器上启用WinRM .

    只需尝试从cmd运行命令 winrm quickconfig 作为特定服务器上的管理员以启用WinRM . 之后再试一次 .

    C:\Windows\system32>WinRM quickconfig
     WinRM service is already running on this machine.
     WinRM is not set up to allow remote access to this machine for management.
     The following changes must be made:
    
     Create a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this
     machine.
    
     Make these changes [y/n]? y
    
     WinRM has been updated for remote management.
    
     Created a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this
     machine.
    

相关问题