File tree Expand file tree Collapse file tree
src/AzureArtifactsPowerShellModuleHelper Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,8 +32,19 @@ Import-Module -Name $moduleFilePathToTest -Force
3232
3333function Remove-PsRepository ([string ] $feedUrl )
3434{
35- Get-PSRepository | Where-Object { $_.SourceLocation -ieq $feedUrl } | Unregister-PSRepository
36- Get-PSRepository | Where-Object { $_.SourceLocation -ieq $feedUrl } | Should - BeNullOrEmpty
35+ $repositories = Get-PSRepository
36+
37+ # PowerShellGet v2 uses SourceLocation and v3 uses Uri for the feed URL of Get-PSRepository, so check both.
38+ if ($repositories -and $repositories [0 ].PSObject.Properties.Name -contains ' SourceLocation' )
39+ {
40+ $repositories | Where-Object { $_.SourceLocation -ieq $feedUrl } | Unregister-PSRepository
41+ Get-PSRepository | Where-Object { $_.SourceLocation -ieq $feedUrl } | Should - BeNullOrEmpty
42+ }
43+ else
44+ {
45+ $repositories | Where-Object { $_.Uri -ieq $feedUrl } | Unregister-PSRepository
46+ Get-PSRepository | Where-Object { $_.Uri -ieq $feedUrl } | Should - BeNullOrEmpty
47+ }
3748}
3849
3950function Remove-PowerShellModule ([string ] $powerShellModuleName )
Original file line number Diff line number Diff line change @@ -90,10 +90,18 @@ function Register-AzureArtifactsPSRepository
9090 {
9191 $psRepositories = Get-PSRepository
9292
93- # Old versions of PowerShellGet use SourceLocation and newer ones use Uri for the feed URL, so check both.
94- [PSCustomObject ] $existingPsRepositoryForFeed = $psRepositories |
95- Where-Object { $_.SourceLocation -ieq $feedUrl -or $_.Uri -ieq $feedUrl } |
96- Select-Object - First 1
93+ # PowerShellGet v2 uses SourceLocation and v3 uses Uri for the feed URL of Get-PSRepository, so check both.
94+ [PSCustomObject ] $existingPsRepositoryForFeed = $null
95+ if ($psRepositories -and $psRepositories [0 ].PSObject.Properties.Name -contains ' SourceLocation' ) {
96+ $existingPsRepositoryForFeed = $psRepositories |
97+ Where-Object { $_.SourceLocation -ieq $feedUrl } |
98+ Select-Object - First 1
99+ } else {
100+ $existingPsRepositoryForFeed = $psRepositories |
101+ Where-Object { $_.Uri -ieq $feedUrl } |
102+ Select-Object - First 1
103+ }
104+
97105 [bool ] $psRepositoryIsAlreadyRegistered = ($null -ne $existingPsRepositoryForFeed )
98106 if ($psRepositoryIsAlreadyRegistered )
99107 {
You can’t perform that action at this time.
0 commit comments