Public/Tests/Suspend-StatusCakeHelperTest.ps1
<# .SYNOPSIS Pauses a StatusCake test check .DESCRIPTION Pauses a test. .PARAMETER APICredential Credentials to access StatusCake API .PARAMETER TestID ID of the Test to be removed from StatusCake .PARAMETER TestName Name of the Test to be removed from StatusCake .EXAMPLE C:\PS>Suspend-StatusCakeHelperTest -TestName "Example" Pauses the test called "Example" #> function Suspend-StatusCakeHelperTest { [CmdletBinding(PositionalBinding=$false,SupportsShouldProcess=$true)] Param( [ValidateNotNullOrEmpty()] [System.Management.Automation.PSCredential] $APICredential = (Get-StatusCakeHelperAPIAuth), [Parameter(ParameterSetName='PauseById',Mandatory=$true)] [int]$TestID, [Parameter(ParameterSetName='PauseByName',Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$TestName ) if($TestName) { #If pausing by name check if resource with that name exists if( $pscmdlet.ShouldProcess("StatusCake API", "Retrieve StatusCake Tests")) { $testCheck = Get-StatusCakeHelperTest -APICredential $APICredential -TestName $TestName if(!$testCheck) { Write-Error "No Test with Specified Name Exists [$TestName]" Return $null } elseif($testCheck.GetType().Name -eq 'Object[]') { Write-Error "Multiple Tests with the same name [$TestName] [$($testCheck.TestID)]" Return $null } $TestID = $testCheck.TestID } } elseif($TestID) { #If pausing by ID verify that a resource with the Id already exists if( $pscmdlet.ShouldProcess("StatusCake API", "Retrieve StatusCake Tests")) { $testCheck = Get-StatusCakeHelperTest -APICredential $APICredential -TestID $TestID if(!$testCheck) { Write-Error "No Test with Specified ID Exists [$TestID]" Return $null } $TestID = $testCheck.TestID } } if( $pscmdlet.ShouldProcess("StatusCake API", "Suspend StatusCake Test")) { $result = Set-StatusCakeHelperTest -APICredential $APICredential -TestID $testID -Paused $true } Return $result } |