Public/Get-JiraIssueAttachment.ps1
function Get-JiraIssueAttachment { # .ExternalHelp ..\JiraPS-help.xml [CmdletBinding()] param( [Parameter( Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName )] [ValidateNotNullOrEmpty()] [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] $errorId = 'ParameterType.NotJiraIssue' $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument $errorTarget = $_ $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $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, [String] $FileName, [Parameter()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty ) begin { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" } process { Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)" Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" # Find the proper object for the Issue $issueObj = Resolve-JiraIssueObject -InputObject $Issue -Credential $Credential if ($issueObj.Attachment) { Write-Debug "[$($MyInvocation.MyCommand.Name)] Found Attachments on the Issue." if ($FileName) { $attachments = $issueObj.Attachment | Where-Object {$_.Filename -like $FileName} } else { $attachments = $issueObj.Attachment } ConvertTo-JiraAttachment -InputObject $attachments } else { $errorMessage = @{ Category = "ObjectNotFound" CategoryActivity = "Searching for resource" Message = "This issue does not have any attachments" } Write-Error @errorMessage } } end { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete" } } |