gpt4 book ai didi

powershell - 为什么powershell脚本跳到最后?

转载 作者:行者123 更新时间:2023-12-03 05:52:05 26 4
gpt4 key购买 nike

我有一个小 Powershell 脚本,应该在本地部署一些服务结构应用程序:

我尝试像这样执行它:

.\Deploy.ps1 -ArtifactPath C:\packages\EnterpriseAPIPackages201710109749b

由于某种原因,它跳到脚本的最后一行!

enter image description here

我做错了什么?如何让所有行都执行?

Param
(
[String]
$ArtifactPath
)

$LocalFolder = Split-Path -parent $MyInvocation.MyCommand.Path

$DeployScriptFile = "$LocalFolder\Scripts\Deploy-FabricApplication.ps1"

$ConfigFilePath = "$LocalFolder\config.xml"

$ConfigFilePath = Resolve-Path $ConfigFilePath

[Xml]$configParameters = (Get-Content $ConfigFilePath)

$services = $configParameters.DeploymentConfiguration.Microservices

if (!$ArtifactPath)
{
$ArtifactPath = $LocalFolder
}

$ApplicationPackageFiles = Get-ChildItem -Path $ArtifactPath -Filter ApplicationManifest.xml -Recurse -Force -ErrorAction SilentlyContinue

foreach($ApplicationPackageFile in $ApplicationPackageFiles)
{
$ApplicationPackagePath = Split-Path -Parent -Path $($ApplicationPackageFile.FullName)
$ProjectName = Split-Path $ApplicationPackagePath -Leaf
Write-Host "Start PowerShell script to deploy Microservice to Service Fabric: ApplicationPackageName: $($ProjectName)"

$ScriptBlock = [ScriptBlock]::Create("$DeployScriptFile -ApplicationPackagePath '$ApplicationPackagePath'")

Invoke-Command -ScriptBlock $ScriptBlock
}

Read-Host -Prompt "Press Enter to exit"

最佳答案

What am I doing wrong? How do I get all the lines to execute?

看来你的代码没有任何问题。我假设 $ApplicationPackageFiles 变量中没有任何内容,因此 foreach 子句不会被执行。

您可以使用以下方法之一对其进行调试:

1.直接打印$ApplicationPackageFiles变量到控制台

 Write-Host "ApplicationPackageFiles value: $ApplicationPackageFiles" 

2.在foreach前后添加输出信息进行检查。

Write-Host "Before loop..." 
foreach($ApplicationPackageFile in $ApplicationPackageFiles)
{
xxxxx
}
Write-Host "After loop..."

关于powershell - 为什么powershell脚本跳到最后?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46679021/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com