Public/Invoke-OriAzBopDownloadPackage.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
<#
.DESCRIPTION This function Download artifact .SYNOPSIS This function Download artifact .PARAMETER RepositoryCredential Credentials for connection to repository .PARAMETER Artifacts String array of Artifacts to download. e.g. @(@{Name = 'Ori.Online.Website'; Version='4.0.0-UAT-236612'}, @{Name = 'Ori.Online.Common.Web'; Version='4.0.0-UAT-236612'}) .EXAMPLE $password = ConvertTo-SecureString 'password1' -AsPlainText -Force $RepositoryCredential = New-Object System.Management.Automation.PSCredential 'Wuhan@myemail.com',$password Invoke-OriAzBopDownloadPackage ` -RepositoryCredential $RepositoryCredential ` -Artifacts @(@{Name = 'Ori.Online.Website'; RequiredVersion = '4.250.6224.1-UAT-2003141613'}) #> function Invoke-OriAzBopDownloadPackage { [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "Low")] param ( [parameter(Mandatory = $true, HelpMessage = 'Credentials for connection to repository')] [PSCredential] $RepositoryCredential, [parameter(Mandatory = $false, HelpMessage = "String array of Artifacts to download. e.g. @(@{Name = 'Ori.Online.Website'; Version='4.0.0-UAT-236612'}, @{Name = 'Ori.Online.Common.Web'; Version='4.0.0-UAT-236612'})")] [PSObject[]] $Artifacts ) #in case of any error we want to stop execution, in stderr having the error. Use try-catch to handle errors if needed. $ErrorActionPreference = "Stop"; Write-Output "-- Invoke-OriAzBopDownloadPackage --" Write-Output "RepositoryCredential: $(ConvertTo-Json $RepositoryCredential) " Write-Output "Artifacts: $(ConvertTo-Json $Artifacts) " Write-Output "-- Invoke-Commnad on machine [$($env:COMPUTERNAME)]" $failInTheEnd = $false foreach ($OneArtifact in $Artifacts) { $OneArtifact += @{Credential = $RepositoryCredential } $PackageToDownload = Find-Package @OneArtifact if ([string]::IsNullOrEmpty($PackageToDownload)) { Write-Output "Such artifact not found $(Convertto-Json $OneArtifact)" $failInTheEnd = $true } else { Install-Package @OneArtifact } } if ($failInTheEnd) { Write-Error "Some artifacts was not found. See previous log." } Write-Output "-- End of Invoke-Commnad on machine [$($env:COMPUTERNAME)]" Write-Output "-- End of Invoke-OriAzBopDownloadPackage --" } |