Get-WinGetSource.ps1 (2301B)
1 Function Get-WinGetSource 2 { 3 <# 4 .SYNOPSIS 5 Gets the configured sources. 6 Additional options can be provided to filter the output, much like the search command. 7 8 .DESCRIPTION 9 By running this cmdlet with the will retrieve the sources configured on the local system. 10 11 .PARAMETER Filter 12 Used to search for the source by name. 13 14 .PARAMETER Name 15 Used to specify the Name of the package 16 17 .PARAMETER VerboseLog 18 Used to provide verbose logging for the Windows Package Manager. 19 20 .EXAMPLE 21 Get-WinGetSource "winget" 22 23 This example returns the configured source named "winget". 24 25 .EXAMPLE 26 Get-WinGetSource "winget" -Name "msstore" 27 28 This example returns the configured source named "msstore". 29 30 .EXAMPLE 31 Find-WinGetPackage -Name "Package" 32 33 This example searches for a package containing "Package" as a valid name on all configured sources. 34 #> 35 36 PARAM( 37 [Parameter()] [string] $Name, 38 [Parameter()] [switch] $VerboseLog 39 ) 40 BEGIN 41 { 42 [string[]] $WinGetArgs = "Source", "Export" 43 [WinGetSource[]] $Result = @() 44 [string[]] $IndexTitles = @("Name", "Argument") 45 46 if($PSBoundParameters.ContainsKey('Filter')){ 47 ## Search for the Name 48 $WinGetArgs += "--Filter", $Filter.Replace("…", "") 49 } 50 if($PSBoundParameters.ContainsKey('Name')){ 51 ## Search for the Name 52 $WinGetArgs += "--Name", $Name.Replace("…", "") 53 } 54 if($VerboseLog){ 55 ## Search for the Name 56 $WinGetArgs += "--Verbose-Logs" 57 } 58 } 59 PROCESS 60 { 61 $List = Invoke-WinGetCommand -WinGetArgs $WinGetArgs -IndexTitles $IndexTitles -JSON 62 63 foreach ($Obj in $List) { 64 #$Result += [WinGetSource]::New($Obj.Name, $Obj.Argument) 65 $Result += @{ 66 Name = $Obj.Name 67 Argument = $Obj.Arg 68 Data = $Obj.Data 69 Identifier = $Obj.Identifier 70 Type = $Obj.Type 71 } 72 } 73 } 74 END 75 { 76 return $Result 77 } 78 } 79 80 Export-ModuleMember -Function Get-WinGetSource