Trying to append the index value of a for loop to the end of a string, but I'm having some trouble getting the desired result.
Here's a short code block of what I'm working with:
EDIT:
$apiKey = "ZZZ-ZZZZZ"
$octoHeader = @{ "X-Octopus-ApiKey" = $apiKey }
# GET Source deployment process from Deployment Scaffold project
$json = irm "http://octopusserver/api/deploymentprocesses/deploymentprocess-projects-123" -Headers $octoHeader
$DeploymentSteps = $json.Steps
# Hash table to hold steps
$steps = @{}
function Get-StepType
(
$StepType
)
{
foreach ( $Step in $DeploymentSteps | where { $_.Name -eq $StepType } )
{
return $Step
}
}
function Copy-Steps
(
$StepType,
$StepCount
)
{
$Step = Get-StepType -StepType $StepType
1..$StepCount | % {
$Step.Id = ''
$Step.Name += $_
# Add step to hash
$steps.Add("step$($steps.Count + 1)", $step)
}
}
Copy-Steps -StepType 'Service' -StepCount 2
$steps
And this is the result:
Name Value
---- -----
step1 @{Id=; Name=Service12; Actions=S...
step2 @{Id=; Name=Service12; Actions=S...
The result I'm after is: Name=Service - 1, Name=Service - 2, etc. I see what's happening, but I'm not sure the proper way to get what I'm after.
Any help is greatly appreciated.