function Get-ChocolateySourcesV2 { <# .SYNOPSIS Returns a list of locally configured chocolatey feed objects. #> [CmdletBinding()] Param( [Parameter(Mandatory = $false)] [string]$hostname = "localhost", [Parameter(Mandatory = $false)] [Alias("IncludeDisabled")] [switch]$includeDisabledSources ) $logLead = (Get-LogLeadName) $sb = { [xml](Get-Content "C:\ProgramData\chocolatey\config\chocolatey.config") } $sources = @() if (Compare-StringToLocalMachineIdentifiers -stringToCheck $hostname) { $sources = (Invoke-Command -ScriptBlock $sb).chocolatey.sources } else { $sources = (Invoke-Command -ComputerName $hostname -ScriptBlock $sb).chocolatey.sources } $alkamiHostname = 'packagerepo.orb.alkamitech.com' $sdkHostname = 'feeds.alkamitech.com' $defaultFeed = 'chocolatey.org' $resultSources = @() foreach ($source in $sources.source) { $uri = [System.Uri]::new($source.value) $isSdkFeed = $uri.Host -eq $sdkHostname $isAlkamiFeed = $uri.Host -eq $alkamiHostname $isDefault = $source.value -match $defaultFeed $isSre = ($source.value -match 'SRE') -or ($source.value -match 'nuget.internal') $priority = [int]$source.Priority $properties = @{ Name = $source.Id Source = $source.Value Priority = $priority Disabled = [bool]::Parse($source.Disabled) IsDefault = $isDefault IsSDK = $isSdkFeed Ordering = ($priority + (2 * [int]$isAlkamiFeed) + [int]$isSdkFeed - [int]$isSre - (2 * [int]$isDefault)) } $source = New-Object -TypeName PSObject -Prop $properties if (!$source.Disabled -or ($includeDisabledSources -and $source.Disabled)) { $resultSources += $source } else { Write-Host "$logLead : Skipping return of [$($source.Name)] with url [$($source.Source)] due to it is disabled, and no flag is provided to include disabled feeds" } } $resultSources = $resultSources | Sort-Object -Property Ordering -Descending return $resultSources }