Scripts/Set-BPAProcess.ps1
function Set-BPAProcess { <# .SYNOPSIS Sets properties of an AutoMate BPA process. .DESCRIPTION Set-BPAProcess can change properties of a process object. .PARAMETER InputObject The object to modify. .PARAMETER Notes The new notes to set on the object. .PARAMETER CommandLine The command to run. .PARAMETER WorkingDirectory The working directory to use when running the command. .PARAMETER EnvironmentVariables Environment variables to load when running the command. .PARAMETER RunningContext The context to execute the command in: Default, SH or Bash. .PARAMETER CompletionState The completion state (staging level) to set on the object. .INPUTS The following BPA object types can be modified by this function: Process .EXAMPLE # Change command for a process Get-BPAProcess "Start Service" | Set-BPAProcess -Notes "Starts a service" .EXAMPLE # Empty notes for all agent groups Get-BPAProcess | Set-BPAProcess -RunningContext Bash .NOTES Author(s): : David Seibel Contributor(s) : Date Created : 11/07/2016 Date Modified : 07/02/2018 .LINK https://github.com/davidseibel/PoshBPA #> [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact="Medium")] param( [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = "ByInputObject")] $InputObject, [Parameter(Mandatory = $true, ParameterSetName = "ByInstance")] [ValidateScript({ if ($_.TypeName -eq "Process") { $true } else { throw [System.Management.Automation.PSArgumentException]"Instance is not a Process!" } })] $Instance, [Parameter(ParameterSetName = "ByInputObject")] [string]$Notes, [Parameter(ParameterSetName = "ByInputObject")] [ValidateNotNullOrEmpty()] [string]$CommandLine, [Parameter(ParameterSetName = "ByInputObject")] [string]$WorkingDirectory, [Parameter(ParameterSetName = "ByInputObject")] [string]$EnvironmentVariables, [Parameter(ParameterSetName = "ByInputObject")] [BPAProcessRunningContext]$RunningContext, [Parameter(ParameterSetName = "ByInputObject")] [BPACompletionState]$CompletionState ) PROCESS { switch ($PSCmdlet.ParameterSetName) { "ByInputObject" { foreach ($obj in $InputObject) { if ($obj.TypeName -eq "Process") { $updateObject = Get-BPAProcess -ID $obj.ID -BPAServer $obj.BPAServer $shouldUpdate = $false if ($PSBoundParameters.ContainsKey("CommandLine")) { if ($updateObject.CommandLine -ne $CommandLine) { $updateObject.CommandLine = $CommandLine $shouldUpdate = $true } } if ($PSBoundParameters.ContainsKey("WorkingDirectory")) { if ($updateObject.WorkingDirectory -ne $WorkingDirectory) { $updateObject.WorkingDirectory = $WorkingDirectory $shouldUpdate = $true } } if ($PSBoundParameters.ContainsKey("EnvironmentVariables")) { if ($updateObject.EnvironmentVariables -ne $EnvironmentVariables) { $updateObject.EnvironmentVariables = $EnvironmentVariables $shouldUpdate = $true } } if ($PSBoundParameters.ContainsKey("RunningContext")) { if ($updateObject.RunProcessAs -ne $RunningContext) { $updateObject.RunProcessAs = $RunningContext $shouldUpdate = $true } } if ($PSBoundParameters.ContainsKey("Notes")) { if ($updateObject.Notes -ne $Notes) { $updateObject.Notes = $Notes $shouldUpdate = $true } } if ($PSBoundParameters.ContainsKey("CompletionState")) { if ($updateObject.CompletionState -ne $CompletionState.value__) { $updateObject.CompletionState = $CompletionState.value__ $shouldUpdate = $true } } if ($shouldUpdate) { $updateObject | Set-BPAObject } else { Write-Verbose "$($obj.TypeName) '$($obj.Name)' already contains the specified values." } } else { Write-Error -Message "Unsupported input type '$($obj.TypeName)' encountered!" -TargetObject $obj } } } "ByInstance" { $updateObject = $Instance.PSObject.Copy() $validated = $true if ($updateObject.ID -notmatch $BPAGuidRegex) { $validated = $false throw "$($Instance.TypeName) '$($Instance.Name)' has an ID that is not a valid GUID!" } if ($validated) { $updateObject | Set-BPAObject } } } } } |