Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions src/Public/New-CCMDeploymentStep.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ function New-CCMDeploymentStep {
.PARAMETER TargetGroup
The group(s) the step will target

.PARAMETER ExecutionTimeoutSeconds
How long to wait for the step to timeout. Defaults to 14400 (4 hours)
.PARAMETER ExecutionTimeout
How long to wait, in seconds, for the step to timeout. Defaults to 14400 (4 hours)

.PARAMETER MachineContactTimeout
How long to wait, in minutes, for computers to check in to start the deployment before timing out.
Defaults to 0 (no timeout).

.PARAMETER FailOnError
Fail the step if there is an error. Defaults to True
Expand Down Expand Up @@ -98,8 +102,14 @@ function New-CCMDeploymentStep {
$TargetGroup = @(),

[Parameter()]
[Alias('ExecutionTimeoutSeconds', 'ExecutionTimeoutInSeconds')]
[string]
$ExecutionTimeout = '14400',

[Parameter()]
[Alias('MachineContactTimeoutInMinutes', 'MachineContactTimeoutMinutes')]
[string]
$ExecutionTimeoutSeconds = '14400',
$MachineContactTimeout = 0,

[Parameter()]
[switch]
Expand Down Expand Up @@ -144,18 +154,20 @@ function New-CCMDeploymentStep {
switch ($PSCmdlet.ParameterSetName) {
'Basic' {
$Body = @{
Name = "$Name"
DeploymentPlanId = "$(Get-CCMDeployment -Name $Deployment | Select-Object -ExpandProperty Id)"
DeploymentStepGroups = @(
Get-CCMGroup -Group $TargetGroup | Select-Object Name, Id | ForEach-Object {
[pscustomobject]@{ groupId = $_.id; groupName = $_.name }
}
name = $Name
deploymentPlanId = (Get-CCMDeployment -Name $Deployment).id
deploymentStepGroups = @(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
deploymentStepGroups = @(
deploymentStepGroups = [System.Collections.Generic.List[psobject]]@(

This cast ensures the collection is always preserved during json serialization; it seems some versions of powershell unwrap a one-element array, but leave other collection types intact.

Get-CCMGroup -Group $TargetGroup | Select-Object -Property @(
@{ Name = "groupId"; Expression = { $_.id } }
@{ Name = "groupName"; Expression = { $_.name } }
)
)
ExecutionTimeoutInSeconds = "$ExecutionTimeoutSeconds"
RequireSuccessOnAllComputers = "$RequireSuccessOnAllComputers"
failOnError = "$FailOnError"
validExitCodes = "$($validExitCodes -join ',')"
script = "$($ChocoCommand.ToLower())|$($PackageName)"
executionTimeoutInSeconds = $ExecutionTimeout
machineContactTimeoutInMinutes = $MachineContactTimeout
requireSuccessOnAllComputers = $RequireSuccessOnAllComputers
failOnError = $FailOnError
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
executionTimeoutInSeconds = $ExecutionTimeout
machineContactTimeoutInMinutes = $MachineContactTimeout
requireSuccessOnAllComputers = $RequireSuccessOnAllComputers
failOnError = $FailOnError
executionTimeoutInSeconds = $ExecutionTimeout
machineContactTimeoutInMinutes = $MachineContactTimeout
requireSuccessOnAllComputers = $RequireSuccessOnAllComputers.IsPresent
failOnError = $FailOnError.IsPresent

JSON serialization doesn't handle these well, it treats a [switch] parameter object as an object with the form { IsPresent: true } rather than a raw boolean, make sure we take the inner property explicitly (this should be fixed below for consistency as well)

validExitCodes = $ValidExitCodes -join ','
script = "{0}|{1}" -f @($ChocoCommand.ToLower(), $PackageName)
} | ConvertTo-Json -Depth 3

$Uri = "$($protocol)://$hostname/api/services/app/DeploymentSteps/CreateOrEdit"
Expand All @@ -181,7 +193,7 @@ function New-CCMDeploymentStep {
}

$irmParams = @{
Uri = "$($Uri)"
Uri = $Uri
Method = "POST"
ContentType = "application/json"
WebSession = $Session
Expand Down