Scripts/Set-BPAWindowConditionControl.ps1

function Set-BPAWindowConditionControl {    
    <#
        .SYNOPSIS
            Modifies an AutoMate BPA window condition control.
 
        .DESCRIPTION
            Set-BPAWindowConditionControl modifies a control in an AutoMate BPA window condition.
 
        .PARAMETER InputObject
            The window condition object to add the control to.
 
        .PARAMETER ID
            The ID of the window control.
 
        .PARAMETER Class
            The class of the control.
 
        .PARAMETER Name
            The name of the control.
 
        .PARAMETER Type
            The type of control.
 
        .PARAMETER Value
            The value of the control.
 
        .PARAMETER XPosition
            The X position of the control on screen.
 
        .PARAMETER YPosition
            The Y position of the control on screen.
 
        .EXAMPLE
            Get-BPACondition "window" | Set-BPAWindowConditionControl -ID "{0cee39da-1f6c-424b-a9bd-eeaf17cbd1f2}" -Class ConsoleWindowClass -Name Close -Type PushButton
 
        .NOTES
            Author(s): : David Seibel
            Contributor(s) :
            Date Created : 02/22/2018
            Date Modified : 02/22/2018
 
        .LINK
            https://github.com/davidseibel/PoshBPA
    #>

    [CmdletBinding(DefaultParameterSetName = "Default")]
    param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        $InputObject,
        
        [Parameter(Mandatory = $true)]
        $ID,        
        $Class,
        $Name,
        $Type,
        $Value,
        $XPosition,
        $YPosition
    )

    PROCESS {
        foreach ($obj in $InputObject) {
            if (($obj.TypeName -eq "Condition") -and ($obj.TriggerType -eq [BPATriggerType]::Window.value__)) {
                $updateObject = Get-BPACondition -ID $obj.ID -BPAServer $obj.BPAServer
                $shouldUpdate = $false
                foreach ($windowcontrol in $updateObject.WindowControl | Where-Object {$_.ID -eq $ID}) {
                    if ($PSBoundParameters.ContainsKey("Class") -and ($windowcontrol.Class -ne $Class)) {
                        $windowcontrol.Class = $Class
                        if ($Class -eq "") {
                            $windowcontrol.CheckClass = $false
                        } else {
                            $windowcontrol.CheckClass = $true
                        }
                        $shouldUpdate = $true
                    }
                    if ($PSBoundParameters.ContainsKey("Name") -and ($windowcontrol.Name -ne $Name)) {
                        $windowcontrol.Name = $Name
                        if ($Name -eq "") {
                            $windowcontrol.CheckName = $false
                        } else {
                            $windowcontrol.CheckName = $true
                        }
                        $shouldUpdate = $true
                    }
                    if ($PSBoundParameters.ContainsKey("Type") -and ($windowcontrol.Type -ne $Type)) {
                        $windowcontrol.Type = $Type
                        if ($Type -eq "") {
                            $windowcontrol.CheckType = $false
                        } else {
                            $windowcontrol.CheckType = $true
                        }
                        $shouldUpdate = $true
                    }
                    if ($PSBoundParameters.ContainsKey("Value") -and ($windowcontrol.Value -ne $Value)) {
                        $windowcontrol.Value = $Value
                        if ($Value -eq "") {
                            $windowcontrol.CheckValue = $false
                        } else {
                            $windowcontrol.CheckValue = $true
                        }
                        $shouldUpdate = $true
                    }
                    if ($PSBoundParameters.ContainsKey("XPosition") -and ($windowcontrol.Xpos -ne $XPosition)) {
                        $windowcontrol.Xpos = $XPosition
                        if ($XPosition -eq "") {
                            $windowcontrol.CheckPosition = $false
                        } else {
                            $windowcontrol.CheckPosition = $true
                        }
                        $shouldUpdate = $true
                    }
                    if ($PSBoundParameters.ContainsKey("YPosition") -and ($windowcontrol.Ypos -ne $YPosition)) {
                        $windowcontrol.Ypos = $YPosition
                        if ($YPosition -eq "") {
                            $windowcontrol.CheckPosition = $false
                        } else {
                            $windowcontrol.CheckPosition = $true
                        }
                        $shouldUpdate = $true
                    }
                }
                if ($shouldUpdate) {
                    $updateObject | Set-BPAObject
                }
            } else {
                Write-Error -Message "Unsupported input type '$($obj.TypeName)' and trigger type '$($obj.TriggerType -as [BPATriggerType])' encountered!" -TargetObject $obj
            }
        }
    }
}