Public/Unregister-OriAzBopRepository.ps1
<#
.DESCRIPTION This function Unregister repository .SYNOPSIS This function Unregister repository .PARAMETER DevOpsAccount The name of the dev ops account. Default value is 'oriflame' .PARAMETER ProjectName String array of project name in Dev Ops. e.g. Online, GlobalDev, DeploymentPackages .PARAMETER SkipPrompt When is set it does not prompt .EXAMPLE $password = ConvertTo-SecureString 'heslo1' -AsPlainText -Force $RepositoryCredential = New-Object System.Management.Automation.PSCredential 'Wuhan@mydomanin.com',$password Unregister-OriAzBopRepository ` -DevOpsAccount 'oriflame' ` -ProjectName @('DeploymentPackages') #> function Unregister-OriAzBopRepository { [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "Low")] param ( [parameter(Mandatory = $false, HelpMessage = 'The name of the dev ops account')] [string] $DevOpsAccount = $Script:VstsAccount, [parameter(Mandatory = $true, HelpMessage = 'String array of project name in Dev Ops. e.g. Online, GlobalDev, DeploymentPackages')] [string[]] $ProjectName, [parameter(Mandatory = $false, HelpMessage = 'When is set it does not prompt')] [Switch] $SkipPrompt ) #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-Verbose -Message ("[ START: {0}:{1} (v.{2}) ]" -f $Local:MyInvocation.MyCommand.Source, $Local:MyInvocation.MyCommand.Name, $Local:MyInvocation.MyCommand.Version) foreach ($arg in $PSBoundParameters.GetEnumerator()) { if ([string]::IsNullOrEmpty($arg.Value)) { Write-Debug -Message ("[null] {0}: {1}" -f $arg.Key, $arg.Value) -ErrorAction SilentlyContinue } else { Write-Debug -Message ("[{2}] {0}: {1}" -f $arg.Key, $arg.Value, $arg.Value.GetType().Name) -ErrorAction SilentlyContinue } } Write-Debug "-- Invoke-Commnad on machine [$($env:COMPUTERNAME)]" $registeredFeeds = Get-PSRepository foreach ($feed in $ProjectName) { #$uri = 'https://pkgs.dev.azure.com/{0}/_packaging/{1}/nuget/v2' -f $DevOpsAccount, $feed if ($registeredFeeds.SourceLocation -like "*$feed*") { Write-Debug "Unregister [$feed] NuGet feed."; if ($SkipPrompt -or $PSCmdlet.ShouldProcess("Unregister repository $feed", $MachineName)) { $UnregisterRepositoryParams = @{ Name = $feed } Unregister-OriAzBopInternalPSRepository ` -UnregisterRepositoryParams $UnregisterRepositoryParams ` -Verbose:$VerbosePreference ` -Debug:$DebugPreference } } } Write-Debug "-- End of Invoke-Commnad on machine [$($env:COMPUTERNAME)]" Write-Verbose -Message ("[ END: {0} ]" -f $Local:MyInvocation.MyCommand.Name) } |