Public/Remove-JiraRemoteLink.ps1
function Remove-JiraRemoteLink { [CmdletBinding( ConfirmImpact = 'High', SupportsShouldProcess )] param( [Parameter( Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName )] [ValidateNotNullOrEmpty()] [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { $errorItem = [System.Management.Automation.ErrorRecord]::new( ([System.ArgumentException]"Invalid Type for Parameter"), 'ParameterType.NotJiraIssue', [System.Management.Automation.ErrorCategory]::InvalidArgument, $_ ) $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# #ToDo:CustomClass Once we have custom classes, this check can be done with Type declaration #> } else { return $true } } )] [Alias("Key")] [Object[]] $Issue, [Parameter( Mandatory )] [Int[]] $LinkId, [PSCredential] $Credential, [Switch] $Force ) begin { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" $server = Get-JiraConfigServer -ErrorAction Stop $resourceURi = "$server/rest/api/latest/issue/{0}/remotelink/{1}" if ($Force) { Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] -Force was passed. Backing up current ConfirmPreference [$ConfirmPreference] and setting to None" $oldConfirmPreference = $ConfirmPreference $ConfirmPreference = 'None' } } process { Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)" Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" foreach ($_issue in $Issue) { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Processing [$Issue]" Write-Debug "[$($MyInvocation.MyCommand.Name)] Processing `$Issue [$Issue]" # Find the proper object for the Issue $issueObj = Resolve-JiraIssueObject -InputObject $_issue -Credential $Credential foreach ($_link in $LinkId) { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Processing [$_link]" Write-Debug "[$($MyInvocation.MyCommand.Name)] Processing `$_link [$_link]" $parameter = @{ URI = $resourceURi -f $issueObj.Key, $_link Method = "DELETE" Credential = $Credential } Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking JiraMethod with `$parameter" if ($PSCmdlet.ShouldProcess($issueObj.Key, "Remove RemoteLink '$_link'")) { Invoke-JiraMethod @parameter } } } } end { if ($Force) { Write-DebugMessage "[Remove-JiraGroupMember] Restoring ConfirmPreference to [$oldConfirmPreference]" $ConfirmPreference = $oldConfirmPreference } Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete" } } |