Functions/Public/Remove-SaltSchedule.ps1
<#
.SYNOPSIS Removes a Schedule from SaltStack Enterprise. .DESCRIPTION This function will use the Invoke-SaltStackAPIMethod command to use the remove method on the schedule resource to return a list of Schedules. .EXAMPLE Remove-SaltSchedule -SaltConnection $SaltConnection -Name ScheduleA This will remove the Schedule ScheduleA using it's name. .EXAMPLE Remove-SaltSchedule -SaltConnection $SaltConnection -UUID e33ef27b-8a29-45c1-972c-c2a5f5472a29 This will remove the Schedule with the UUID e33ef27b-8a29-45c1-972c-c2a5f5472a29. .OUTPUTS PSCustomObject .NOTES General notes .LINK #> function Remove-SaltSchedule { [CmdletBinding(SupportsShouldProcess = $true,DefaultParameterSetName = 'Name')] param ( # Salt connection object [Parameter(Mandatory = $true)] [Parameter(ParameterSetName = 'Name')] [Parameter(ParameterSetName = 'UUID')] [SaltConnection] $SaltConnection, # Name [Parameter(ParameterSetName = 'Name')] [String] $Name, # UUID [Parameter(ParameterSetName = 'UUID')] [String] $UUID ) $splat = @{ SaltConnection = $SaltConnection } if ($name) { $splat.Add('Name',$Name) $splat.Add('ExactMatch',$true) } if ($UUID) { $splat.Add('UUID',$UUID) } $schedule = Get-SaltSchedule @splat if ($schedule.Count -eq 0) { throw "No Schedules found with the information provided." } elseif ($schedule.Count -gt 1) { throw "More than one Schedule was found matching the information provided." } $scheduleID = $schedule.uuid $arguments = @{ uuid = $scheduleID } $return = Invoke-SaltStackAPIMethod -SaltConnection $SaltConnection -Resource schedule -Method remove -Arguments $arguments if ($return.error) { $errorDetail = $return.error.detail.state $errorMessage = $return.error.message Write-Error "$errorMessage - $errorDetail" } else { Write-Output -InputObject $return } } |