Public/Unregister-OriAzBopRepository.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
68
69
70
71
72
73
74
75
76
<#
.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-Output "-- Unregister-OriAzBopRepository --"
  Write-Output "MachineName: $MachineName"
  Write-Output "DevOpsAccount: $DevOpsAccount"
  Write-Output "ProjectName: $ProjectName"
  Write-Output "-- 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-Output "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-Output "-- End of Invoke-Commnad on machine [$($env:COMPUTERNAME)]"
  Write-Debug "-- End of Unregister-OriAzBopRepository --"
}