winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

Add-WinGetSource.ps1 (2299B)


      1 Function Add-WinGetSource
      2 {
      3     <#
      4         .SYNOPSIS
      5         Adds a source to the Windows Package Manager. 
      6         
      7         .DESCRIPTION
      8         By running this cmdlet with the will add a new source to the Windows Package Manager.
      9 
     10         .PARAMETER Name
     11         Used to specify the Name of the source
     12 
     13         .PARAMETER Arg
     14         Used to specify the URL for the source
     15 
     16         .PARAMETER Type
     17         Used to specify the Type of source to add
     18         Currently the only two valid values are "Microsoft.Rest" and "Microsoft.PreIndexed.Package"
     19 
     20         .PARAMETER Header
     21         Used to specify the value to pass as the "Windows-Package-Manager" HTTP header for a REST source.
     22 
     23         .PARAMETER AcceptSourceAgreement
     24         Used to explicitly accept any agreement required by the source.
     25 
     26         .PARAMETER VerboseLog
     27         Used to provide verbose logging for the Windows Package Manager.
     28         
     29         .EXAMPLE
     30         Add-WinGetSource -Name "custom" -Argument "https://contoso.com/" -Type "Microsoft.Rest"
     31 
     32         This example adds a new source to the Windows Package Manager named "custom"
     33 
     34         .EXAMPLE
     35         Add-WinGetSource -Name "custom" -Argument "https://contoso.com/" -Type "Microsoft.Rest" -Header "string" -AcceptSourceAgreement:$true
     36 
     37         This example adds a new source to the Windows Package Manager named "custom" and passes the value "string" in the Windows-Package-Manager HTTP header to the source.
     38     #>
     39 
     40     PARAM(
     41         [Parameter(Mandatory=$true)] [string]   $Name,
     42         [Parameter(Mandatory=$true)] [string]   $Argument,
     43         [Parameter(Mandatory=$true)] [ValidateSet("Microsoft.Rest", "Microsoft.PreIndexed.Package")] [string]$Type,
     44         [Parameter()] [ValidateLength(1, 1024)] $Header,
     45         [Parameter()] [bool]                    $AcceptSourceAgreement
     46     )
     47     BEGIN
     48     {
     49         if ($AcceptSourceAgreement) {$acceptOption = '--accept-source-agreements'}
     50         [string] $WinGetArgs  = "Source Add --Name {0} --Arg {1} --Type {2} {3}" -f $Name, $Argument, $Type, $acceptOption 
     51     }
     52     PROCESS
     53     {
     54        Start-Process  -FilePath "winget.exe" -ArgumentList $WinGetArgs -Wait       
     55     }
     56     END
     57     {
     58         #Don't do this unless you are in a class 
     59         #return
     60     }
     61 }
     62 
     63 Export-ModuleMember -Function Add-WinGetSource