Skip to content

Commit

Permalink
Merge pull request #47 from msfreaks/2411.1
Browse files Browse the repository at this point in the history
Added winget admx
  • Loading branch information
msfreaks authored Nov 15, 2024
2 parents 0fcc016 + 86ea33d commit 20ddf52
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 6 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
* Add parameter to clean old Office ADMX from Central Policy Store location
* Add parameter to clean old Adobe Reader ADMX from Central Policy Store location

## 2411
## 2411.1

* Added admx for Microsoft Winget [#40](https://github.com/msfreaks/EvergreenAdmx/issues/40)

## 2411.0

* Changed Get-WindowsAdmxOnline version return
* Added Admx for Microsoft Windows 11 (24H2)
* Added Admx for Microsoft Windows 11 (24H2) [#45](https://github.com/msfreaks/EvergreenAdmx/issues/45)

## 2402
## 2402.1

* Fixed Get-WindowsAdmxOnline version return
* Improved function Get-WindowsAdmxOnline, added default parameters
Expand Down
108 changes: 106 additions & 2 deletions EvergreenAdmx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#region init
<#PSScriptInfo
.VERSION 2411.0
.VERSION 2411.1
.GUID 999952b7-1337-4018-a1b9-499fad48e734
Expand Down Expand Up @@ -96,7 +96,7 @@ param(
[switch] $UseProductFolders,
[Parameter(Mandatory = $False)]
[System.String] $CustomPolicyStore = $null,
[Parameter(Mandatory = $False)][ValidateSet("Custom Policy Store", "Windows 10", "Windows 11", "Microsoft Edge", "Microsoft OneDrive", "Microsoft Office", "FSLogix", "Adobe Acrobat", "Adobe Reader", "BIS-F", "Citrix Workspace App", "Google Chrome", "Microsoft Desktop Optimization Pack", "Mozilla Firefox", "Zoom Desktop Client", "Azure Virtual Desktop")]
[Parameter(Mandatory = $False)][ValidateSet("Custom Policy Store", "Windows 10", "Windows 11", "Microsoft Edge", "Microsoft OneDrive", "Microsoft Office", "FSLogix", "Adobe Acrobat", "Adobe Reader", "BIS-F", "Citrix Workspace App", "Google Chrome", "Microsoft Desktop Optimization Pack", "Mozilla Firefox", "Zoom Desktop Client", "Azure Virtual Desktop", "Microsoft Winget")]
[System.String[]] $Include = @("Windows 11", "Microsoft Edge", "Microsoft OneDrive", "Microsoft Office"),
[Parameter(Mandatory = $False)]
[switch] $PreferLocalOneDrive = $False
Expand Down Expand Up @@ -1487,6 +1487,35 @@ function Get-AzureVirtualDesktopAdmxOnline
}
}

function Get-WingetAdmxOnline
{
<#
.SYNOPSIS
Returns latest Version and Uri for Winget-cli ADMX files
#>

try
{

# define github repo
$repo = "microsoft/winget-cli"
# grab latest release properties
$latest = ((Invoke-WebRequest -UseDefaultCredentials -Uri "https://api.github.com/repos/$($repo)/releases" -UseBasicParsing | ConvertFrom-Json) | Where-Object { $_.name -notlike '*-preview' -and $_.draft -eq $false -and $_.assets.browser_download_url -match 'DesktopAppInstallerPolicies.zip' })[0]

# grab version
$Version = ($latest.tag_name | Select-String -Pattern "(\d+(\.\d+){1,4})" -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value }).ToString()
# grab uri
$URI = $latest.assets.browser_download_url | Where-Object { $_ -like '*/DesktopAppInstallerPolicies.zip'}

# return evergreen object
return @{ Version = $Version; URI = $URI }
}
catch
{
Throw $_
}
}

function Get-FSLogixAdmx
{
<#
Expand Down Expand Up @@ -2583,6 +2612,69 @@ function Get-AzureVirtualDesktopAdmx
return $null
}
}

function Get-WingetAdmx
{
<#
.SYNOPSIS
Process Winget-cli Admx files
.PARAMETER Version
Current Version present
.PARAMETER PolicyStore
Destination for the Admx files
#>

param(
[string]$Version,
[string]$PolicyStore = $null,
[string[]]$Languages = $null
)

$Evergreen = Get-WingetAdmxOnline
$ProductName = "Microsoft winget-cli"
$ProductFolder = ""; if ($UseProductFolders) { $ProductFolder = "\$($ProductName)" }

# see if this is a newer version
if (-not $Version -or [version]$Evergreen.Version -gt [version]$Version)
{
Write-Verbose "Found new version $($Evergreen.Version) for '$($ProductName)'"

# download and process
$OutFile = "$($WorkingDirectory)\downloads\$($Evergreen.URI.Split("/")[-1])"
try
{
# download
Write-Verbose "Downloading '$($Evergreen.URI)' to '$($OutFile)'"
Invoke-WebRequest -UseDefaultCredentials -Uri $Evergreen.URI -UseBasicParsing -OutFile $OutFile

# extract
Write-Verbose "Extracting '$($OutFile)' to '$($env:TEMP)\wingetadmx'"
Expand-Archive -Path $OutFile -DestinationPath "$($env:TEMP)\wingetadmx" -Force

# copy
$SourceAdmx = "$($env:TEMP)\wingetadmx\admx"
$TargetAdmx = "$($WorkingDirectory)\admx$($ProductFolder)"
Copy-Admx -SourceFolder $SourceAdmx -TargetFolder $TargetAdmx -PolicyStore $PolicyStore -ProductName $ProductName -Languages $Languages

# cleanup
Remove-Item -Path "$($env:TEMP)\wingetadmx" -Recurse -Force

return $Evergreen
}
catch
{
Throw $_
}
}
else
{
# version already processed
return $null
}
}

#endregion

#region execution
Expand Down Expand Up @@ -2780,6 +2872,18 @@ else
if ($admx) { if ($admxversions.AzureVirtualDesktop) { $admxversions.AzureVirtualDesktop = $admx } else { $admxversions += @{ AzureVirtualDesktop = @{ Version = $admx.Version; URI = $admx.URI } } } }
}

# Microsoft winget-cli
if ($Include -notcontains 'Microsoft Winget')
{
Write-Verbose "`nSkipping Microsoft Winget"
}
else
{
Write-Verbose "`nProcessing Admx files for Microsoft Winget"
$admx = Get-WingetAdmx -Version $admxversions.Winget.Version -PolicyStore $PolicyStore -Languages $Languages
if ($admx) { if ($admxversions.Winget) { $admxversions.Winget = $admx } else { $admxversions += @{ Winget = @{ Version = $admx.Version; URI = $admx.URI } } } }
}

Write-Verbose "`nSaving Admx versions to '$($WorkingDirectory)\admxversions.xml'"
$admxversions | Export-Clixml -Path "$($WorkingDirectory)\admxversions.xml" -Force
#endregion
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ From this version the 'Includes' will default to "Windows 11", "Microsoft Edge",
This script no longer processes all the products by default. There's no need to comment out any products you don't need anymore.

In 2101.2 the parameter 'Include' was introduced which is an array you can use to specify all products that need to be processed. This parameter is required for the script to be able to run.
Valid entries are "Custom Policy Store", "Windows 10" or "Windows 11", "Microsoft Edge", "Microsoft OneDrive", "Microsoft Office", "FSLogix", "Adobe Acrobat", "Adobe Reader", "BIS-F", "Citrix Workspace App", "Google Chrome", "Microsoft Desktop Optimization Pack", "Mozilla Firefox", "Zoom Desktop Client", "Azure Virtual Desktop".
Valid entries are "Custom Policy Store", "Windows 10" or "Windows 11", "Microsoft Edge", "Microsoft OneDrive", "Microsoft Office", "FSLogix", "Adobe Acrobat", "Adobe Reader", "BIS-F", "Citrix Workspace App", "Google Chrome", "Microsoft Desktop Optimization Pack", "Mozilla Firefox", "Zoom Desktop Client", "Azure Virtual Desktop", "Microsoft Winget".

By default, if you don't use this parameter, only "Windows 11", "Microsoft Edge", "Microsoft OneDrive", "Microsoft Office" is processed.

Expand Down Expand Up @@ -201,6 +201,7 @@ Now supports
* Microsoft OneDrive (local installation or Evergreen)
* Microsoft Windows 10 (1903/1909/2004/20H2/21H1/21H2/22H2)
* Microsoft Windows 11 (21H2/22H2/23H2/24H2)
* Microsoft Winget
* Mozilla Firefox
* Zoom Desktop Client

Expand Down

0 comments on commit 20ddf52

Please sign in to comment.