I have the task of deploying two Windows services created using Topshelf to a test server as part of a continuous integration process.
My target MSBuild file is as follows:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Condition="'$(ConfigurationName)'=='Release'" Name="StopService">
<Exec Command="powershell.exe -NonInteractive -executionpolicy Unrestricted -command "& { &'.\ServiceStop.ps1' } "" ContinueOnError="true" />
</Target>
</Project>
Executes a Powershell script (well, a couple of lines) located in the same folder in a project called ServiceStop.ps:
$service = get-service -ComputerName MyServerName -Name 'MyServiceName'
stop-service -InputObject $service -Verbose
Problem
When I install a queue from a new assembly from TFS, the script succeeds; however, the team get-servicecannot find the service in question, despite the fact that it definitely exists and works. A specific error from the build log is as follows:
Get-Service : Cannot find any service with service name 'MyServiceName' (TaskId:198)
script , , , - .
Powershell. , Powershell, :
$pw = Read-Host -AsSecureString "Enter password"
$pw | ConvertFrom-SecureString | Out-File -Path .\storedPassword.txt
$password = get-content .\storedPassword.txt | convertto-securestring
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist "myAdminAccountName",$password
, , get-service .
PSExec , .
,
PowerShell
stop-service Powershell:
Powershell Get-WmiObject
powershell ConvertTo-SecureString:
, , //, .
!
UPDATE
, Powershell script MSBuild, Powershell.
, , Powershell script, .
, .