Skip to content

Instantly share code, notes, and snippets.

@MrWyss-MSFT
Last active February 21, 2024 13:27
Show Gist options
  • Select an option

  • Save MrWyss-MSFT/d5805b0cfe3708adaf47d19c1d9721fd to your computer and use it in GitHub Desktop.

Select an option

Save MrWyss-MSFT/d5805b0cfe3708adaf47d19c1d9721fd to your computer and use it in GitHub Desktop.
This script will output OMA-URI policies to enable additional sources for the Windows Package Manager (winget).
#[scriptblock]::Create((iwr "https://gist.githubusercontent.com/MrWyss-MSFT/d5805b0cfe3708adaf47d19c1d9721fd/raw").Content).Invoke()
<#PSScriptInfo
.AUTHOR MrWyss-MSFT
#>
<#
.DESCRIPTION
This script will output OMA-URI policies to enable additional sources for the Windows Package Manager (winget).
.EXAMPLE
.\Get-WinGetSourcesAsCSPHtmlEncoded.ps1
.EXAMPLE
.\Get-WinGetSourcesAsCSPHtmlEncoded.ps1 | Where Name -eq winget
.EXAMPLE
.\Get-WinGetSourcesAsCSPHtmlEncoded.ps1 | Where Identifier -eq Microsoft.Winget.Source_8wekyb3d8bbwe | Select -ExpandProperty Value | Clip
#>
Function Get-WinGetSourcesAsCSPHtmlEncoded {
$Sources = winget source export
Foreach ($Source in $Sources) {
$jsonSource = $Source | ConvertFrom-Json
$name = $jsonSource.Name
$identifier = $jsonSource.Identifier
$html_json = [System.Web.HttpUtility]::HtmlEncode($Source)
$OmaUri = "./Device/Vendor/MSFT/Policy/Config/DesktopAppInstaller/EnableAdditionalSources"
$DataType = "String"
$Value = "<enabled/><Data id=`"AdditionalSources`" value=`"1&#xF000;{0}`"/>" -f $html_json
New-Object -TypeName PSCustomObject -Property ([ordered]@{
Name = $name
Identifier = $identifier
OmaUri = $OmaUri
DataType = $DataType
Value = $Value
})
}
}
Get-WinGetSourcesAsCSPHtmlEncoded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment