我在其中一个Azure虚拟机上运行了一个Windows服务。
因此,每当必须进行部署时,我们都要手动复制二进制文件。现在,我正在写一个脚本来完成这个任务。
二进制文件通常是以zip文件夹的形式存在于
MachineA
. 该zip文件夹被复制到
MachineB
(在运行Windows服务的位置)。复制后,将提取文件,然后删除zip文件夹。然后在服务启动之后。
为了做到这一点,我有下面的脚本。
$UserName = "$IPAddress\$adminUsername"
$Password = ConvertTo-SecureString $adminPassword -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($UserName, $Password)
$s = New-PSSession -ComputerName $IPAddress -Credential $psCred
Invoke-Command -Session $s -ScriptBlock {Stop-Service -Name "ServiceName" -Force}
$tempDestPath = $destinationPath + "\*"
Invoke-Command -Session $s -ScriptBlock {param($tempDestPath)Remove-Item $tempDestPath -Recurse} -ArgumentList $tempDestPath
Copy-Item -Path $sourcePath -Destination $destinationPath -ToSession $s -Recurse
$zipFilePath = $destinationPath + "\" + $fileName
Invoke-Command -Session $s -ScriptBlock {param($zipFilePath,$destinationPath) Expand-Archive $zipFilePath -DestinationPath $destinationPath}-ArgumentList $zipFilePath,$destinationPath
#delete zipfolder in destination machine after extraction
Invoke-Command -Session $s -ScriptBlock {param($zipFilePath)Remove-Item âpath $zipFilePath}-ArgumentList $zipFilePath
#start the service
Invoke-Command -Session $s -ScriptBlock {Start-Service -Name "ServiceName"}
当我在中打开Windows PowerShell时,此操作正常
机身
一个接一个地执行这些命令。
但是,当我在ps1文件中放入完全相同的命令并执行该文件时,我会得到以下错误:
At C:\ScriptTest\test.ps1:13 char:95
+ ... -ScriptBlock {Start-Service -Name "ServiceName"}
+ ~~
The string is missing the terminator: ".
At C:\ScriptTest\test.ps1:11 char:42
+ Invoke-Command -Session $s -ScriptBlock {param($zipFilePath)Remov ...
+ ~
Missing closing '}' in statement block or type definition.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
我在哪里找不到这个终结者?我搞不清楚。任何帮助都非常感谢。