Up 2 Down 0

Download Store AppxBundle and Appx

Download-AppxPackage function:

function Download-AppxPackage {
[CmdletBinding()]
param (
  [string]$Uri,
  [string]$Path = "C:\Users\Public\Downloads"
)
   
  process {
    $Path = (Resolve-Path $Path).Path
    #Get Urls to download
    $WebResponse = Invoke-WebRequest -UseBasicParsing -Method 'POST' -Uri 'https://store.rg-adguard.net/api/GetFiles' -Body "type=url&url=$Uri&ring=Retail" -ContentType 'application/x-www-form-urlencoded'
    $LinksMatch = $WebResponse.Links | where {$_ -like '*.appx*'} | where {$_ -like '*_neutral_*' -or $_ -like "*_"+$env:PROCESSOR_ARCHITECTURE.Replace("AMD","X").Replace("IA","X")+"_*"} | Select-String -Pattern '(?<=a href=").+(?=" r)'
    $DownloadLinks = $LinksMatch.matches.value 

    function Resolve-NameConflict{
    #Accepts Path to a FILE and changes it so there are no name conflicts
    param(
    [string]$Path
    )
        $newPath = $Path
        if(Test-Path $Path){
            $i = 0;
            $item = (Get-Item $Path)
            while(Test-Path $newPath){
                $i += 1;
                $newPath = Join-Path $item.DirectoryName ($item.BaseName+"($i)"+$item.Extension)
            }
        }
        return $newPath
    }
    #Download Urls
    foreach($url in $DownloadLinks){
        $FileRequest = Invoke-WebRequest -Uri $url -UseBasicParsing #-Method Head
        $FileName = ($FileRequest.Headers["Content-Disposition"] | Select-String -Pattern  '(?<=filename=).+').matches.value
        $FilePath = Join-Path $Path $FileName; $FilePath = Resolve-NameConflict($FilePath)
        [System.IO.File]::WriteAllBytes($FilePath, $FileRequest.content)
        echo $FilePath
    }
  }
}

WinGet (example) https://apps.microsoft.com/store/detail/appinstallatieprogramma/9NBLGGH4NNS1:
$App = "9NBLGGH4NNS1"
Download-AppxPackage "https://apps.microsoft.com/store/detail/$App" "$ENV:PUBLIC\Downloads"

Microsoft Photos with HEVC and HEIF:
$HEVC = "9NMZLZ57R3T7"
Download-AppxPackage "https://apps.microsoft.com/store/detail/$HEVC" "$ENV:PUBLIC\Downloads"
$HEIF = "9PMMSR1CGPWG"
Download-AppxPackage "https://apps.microsoft.com/store/detail/$HEIF" "$ENV:PUBLIC\Downloads"
$Photos = "9WZDNCRFJBH4"
Download-AppxPackage "https://apps.microsoft.com/store/detail/$Photos" "$ENV:PUBLIC\Downloads"

Install:
Add-AppxPackage "$ENV:PUBLIC\Downloads\Microsoft.UI.Xaml.2.7_7.2208.15002.0_x64__8wekyb3d8bbwe.Appx"
Add-AppxPackage "$ENV:PUBLIC\Downloads\Microsoft.VCLibs.140.00.UWPDesktop_14.0.32530.0_x64__8wekyb3d8bbwe.Appx"
Add-AppxProvisionedPackage -PackagePath "$ENV:PUBLIC\Downloads\Microsoft.DesktopAppInstaller_2021.1207.203.0_neutral_~_8wekyb3d8bbwe.AppxBundle" -SkipLicense -Online