Scripts/Set-BPALogonCondition.ps1
function Set-BPALogonCondition { <# .SYNOPSIS Sets properties of an AutoMate BPA logon condition. .DESCRIPTION Set-BPALogonCondition modifies an existing logon condition. .PARAMETER InputObject The condition to modify. .PARAMETER User The user(s) to wait to logon. Use $null for all users. .PARAMETER Wait Wait for the condition, or evaluate immediately. .PARAMETER Timeout If wait is specified, the amount of time before the condition times out. .PARAMETER TimeoutUnit The unit for Timeout (Seconds by default). .PARAMETER Notes The new notes to set on the object. .NOTES Author(s): : David Seibel Contributor(s) : Date Created : 10/17/2017 Date Modified : 02/08/2018 .LINK https://github.com/davidseibel/PoshBPA #> [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='Medium',DefaultParameterSetName='Default')] param( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] $InputObject, [string[]]$User = @(), [switch]$Wait, [int]$Timeout, [BPATimeMeasure]$TimeoutUnit, [string]$Notes ) PROCESS { foreach ($obj in $InputObject) { if ($obj.TypeName -eq "Condition" -and $obj.TriggerType -eq [BPATriggerType]::Logon.value__) { $update = Get-BPACondition -ID $obj.ID -BPAServer $obj.BPAServer $shouldUpdate = $false if ($PSBoundParameters.ContainsKey("User")) { if (($User.Count -eq 1) -and ($User[0] -like "*;*")) { $User = $User[0].Split(";") } elseif ($null -eq $User) { $User = @() } if ((($update.User | Sort-Object) -join ",") -ne (($User | Sort-Object) -join ",")) { $update.User = $User $shouldUpdate = $true } } if (($PSBoundParameters.ContainsKey("Wait")) -and ($update.Wait -ne $Wait.ToBool())) { $update.Wait = $Wait.ToBool() $shouldUpdate = $true } if (($PSBoundParameters.ContainsKey("Timeout")) -and ($update.Timeout -ne $Timeout)) { $update.Timeout = $Timeout $shouldUpdate = $true } if (($PSBoundParameters.ContainsKey("TimeoutUnit")) -and ($update.TimeoutUnit -ne $TimeoutUnit)) { $update.TimeoutUnit = $TimeoutUnit $shouldUpdate = $true } if (($PSBoundParameters.ContainsKey("Notes")) -and ($update.Notes -ne $Notes)) { $update.Notes = $Notes $shouldUpdate = $true } if ($shouldUpdate) { $update | Set-BPAObject } else { Write-Verbose "$($obj.TypeName) '$($obj.Name)' already contains the specified values." } } else { Write-Error -Message "Unsupported input type '$($obj.TypeName)' and trigger type '$($obj.TriggerType -as [BPATriggerType])' encountered!" -TargetObject $obj } } } } |