Last active
February 21, 2024 13:27
-
-
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[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{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