0

I've got a little Powershell script that is supposed to deploy some service fabric applications locally:

I'm attempting to execute it like this:

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

For some reason it skips to the last line of the script!

enter image description here

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

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"
1
  • 1
    Debbuging? Is something in the $ApplicationPackageFiles variable? Commented Oct 11, 2017 at 6:39

2 Answers 2

1

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

It seems there is nothing wrong with you code. I assume that there is nothing in the $ApplicationPackageFiles variable, so the foreach clause is not be executed.

You debug it with one of the following ways:

1.Print the $ApplicationPackageFiles variable to console directly

 Write-Host "ApplicationPackageFiles value: $ApplicationPackageFiles" 

2.Add the output info before and after foreach to check it.

Write-Host "Before loop..." 
foreach($ApplicationPackageFile in $ApplicationPackageFiles)
{
   xxxxx
}
Write-Host "After loop..." 
Sign up to request clarification or add additional context in comments.

Comments

1

I don't see anything immediately wrong with it. If you copy & pasted it from somewhere, the dashes, newlines, etc, might be wrong (especially if copy/pasting from rich text).

Open your script in PowerShell ISE or vscode and set a breakpoint at the top. Then you can step through line by line to narrow it down.

https://blogs.technet.microsoft.com/heyscriptingguy/2014/12/05/use-the-powershell-debugger/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.