-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Heim Niklaus (ID)
committed
Feb 21, 2022
1 parent
35803fe
commit 961b378
Showing
3 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
Function Edit-bConnectJobSteps() { | ||
<# | ||
.Synopsis | ||
Add, delete, exchange a step to an array of jobsteps or change the step type. | ||
Deploy steps with multiple application are not supported yet! | ||
Jobsteps can be identified either by an application GUID or the jobstep sequence. | ||
Uses New-bConnectJobStep.ps1 to generate jobsteps. | ||
.Parameter JobGuid | ||
Valid GUID of a job to work on. | ||
.Parameter Action | ||
Set the action to execute. | ||
.Parameter ApplicationGuid | ||
Valid GUID of a application to alter. It must be part of a step in the job. | ||
.Parameter NewApplicationGuid | ||
Valid GUID of a application to insert. | ||
.Parameter InstallType | ||
Set the new type of a job step. | ||
.Parameter Sequence | ||
Valid step number to alter. It must be part of a step in the job. | ||
.Parameter IgnoreAssignments | ||
Set the option to alter Jobs even if they are assigned to clients. | ||
.Outputs | ||
Changed Job object (see bConnect documentation for more details) | ||
#> | ||
|
||
Param( | ||
[Parameter(Mandatory=$true)][string]$JobGuid, | ||
[Parameter(Mandatory=$true)][ValidateSet("Add", "Delete", "Exchange", "ChangeType", ignoreCase=$true)][string]$Action, | ||
[Parameter(Mandatory=$false)][string]$ApplicationGuid, | ||
[Parameter(Mandatory=$false)][string]$NewApplicationGuid, | ||
[Parameter(Mandatory=$false)][ValidateSet("Deploy","SoftwareDeployUninstall",ignoreCase=$true)][string]$InstallType, | ||
[Parameter(Mandatory=$false)][int]$Sequence = 9999, | ||
[Parameter(Mandatory=$false)][boolean]$IgnoreAssignments = $false | ||
) | ||
|
||
$JobObj = Get-bConnectJob -JobGuid $JobGuid -Steps | ||
$JobObj_Steps = $JobObj.Steps | ||
$JobObj_Steps_Count = $JobObj_Steps.Count | ||
$JobObj_Steps_New = @() | ||
switch ($Action) { | ||
"Add" { | ||
# Insert a jobstep. | ||
# If a sequence is given, the step is inserted right behind it. | ||
# If application GUID is provided, the step is inserted right behind it. | ||
# If no sequence and no application GUID is present, the step will be inserted at the end. | ||
If($Sequence -gt $JobObj_Steps_Count) { | ||
$Sequence = ($JobObj_Steps_Count + 1) | ||
} | ||
$NewJobStep = New-bConnectJobStep -ApplicationGuid $NewApplicationGuid -Sequence $Sequence -JobStepType $InstallType | ||
$NewSequence = 1 | ||
foreach ($JobStep in $JobObj_Steps) { | ||
$JobStep.Sequence = $NewSequence | ||
$JobObj_Steps_New = $JobObj_Steps_New + $JobStep | ||
$NewSequence++ | ||
|
||
If(($ApplicationGuid -eq $JobStep.Applications.id) -or ($Sequence -eq $NewSequence)) { | ||
$NewJobStep.Sequence = $NewSequence | ||
$JobObj_Steps_New = $JobObj_Steps_New + $NewJobStep | ||
$Sequence = 0 | ||
$ApplicationGuid = "0" | ||
$NewSequence++ | ||
} | ||
} | ||
break | ||
} | ||
"Delete" { | ||
If($Sequence -gt $JobObj_Steps_Count) { | ||
$Sequence = $JobObj_Steps_Count | ||
} | ||
$NewSequence = 1 | ||
foreach ($JobStep in $JobObj_Steps) { | ||
If(($ApplicationGuid -eq $JobStep.Applications.id) -or ($Sequence -eq $NewSequence)) { | ||
$NewSequence++ | ||
$Sequence = 0 | ||
$ApplicationGuid = "0" | ||
|
||
}else { | ||
$JobStep.Sequence = $NewSequence | ||
$JobObj_Steps_New = $JobObj_Steps_New + $JobStep | ||
$NewSequence++ | ||
} | ||
} | ||
break | ||
} | ||
"Exchange" { | ||
If($Sequence -gt $JobObj_Steps_Count) { | ||
$Sequence = $JobObj_Steps_Count | ||
} | ||
$NewJobStep = New-bConnectJobStep -ApplicationGuid $NewApplicationGuid -Sequence $Sequence -JobStepType $InstallType | ||
$NewSequence = 1 | ||
foreach ($JobStep in $JobObj_Steps) { | ||
If(($ApplicationGuid -eq $JobStep.Applications.id) -or ($Sequence -eq $NewSequence)) { | ||
$NewJobStep.Sequence = $NewSequence | ||
$JobObj_Steps_New = $JobObj_Steps_New + $NewJobStep | ||
$Sequence = 0 | ||
$ApplicationGuid = "0" | ||
|
||
}else { | ||
$JobStep.Sequence = $NewSequence | ||
$JobObj_Steps_New = $JobObj_Steps_New + $JobStep | ||
} | ||
$NewSequence++ | ||
} | ||
break | ||
} | ||
"ChangeType" { | ||
$NewSequence = 1 | ||
foreach ($JobStep in $JobObj_Steps) { | ||
If(($ApplicationGuid -eq $JobStep.Applications.id) -or ($Sequence -eq $NewSequence)) { | ||
$JobStep.Type = $InstallType | ||
$Sequence = 0 | ||
$ApplicationGuid = "0" | ||
} | ||
$NewSequence++ | ||
} | ||
$JobObj_Steps_New = $JobObj_Steps | ||
break | ||
} | ||
} | ||
$JobObj.Steps = $JobObj_Steps_New | ||
Edit-bConnectJob -Job $JobObj -IgnoreAssignments $IgnoreAssignments | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Function New-bConnectJobStep() { | ||
<# | ||
.Synopsis | ||
Creates a new list with a Windows job step for Applications. | ||
.Parameter ApplicationGuid | ||
Valid GUID of a application. | ||
.Parameter Sequence | ||
Set the sequence of the job step. | ||
.Parameter JobStepType | ||
Set the type of job step. | ||
.Outputs | ||
Jobstep object (see bConnect documentation for more details) | ||
#> | ||
|
||
[OutputType("System.Management.Automations.PSObject")] | ||
Param( | ||
[Parameter(Mandatory=$true)][string]$ApplicationGuid, | ||
[Parameter(Mandatory=$true)][int]$Sequence = 1, | ||
[Parameter(Mandatory=$true)][ValidateSet("Deploy","SoftwareDeployUninstall",ignoreCase=$true)][string]$JobStepType | ||
) | ||
|
||
$_AppTemp = Get-bConnectApplication -ApplicationGuid $ApplicationGuid | ||
$_new_application_props = [PSCustomObject]@{Id = $ApplicationGuid; Name = $_AppTemp.Vendor + " " + $_AppTemp.Name + " " + $_AppTemp.Version;} | ||
$_new_application_arr = @($_new_application_props) | ||
$_new_jobstep = [PSCustomObject]@{Applications = $_new_application_arr; Sequence = $Sequence; Type = $JobStepType;} | ||
return $_new_jobstep | ||
} |