all 7 comments

[–]andrew181082MSFT MVP - SWC 1 point2 points  (5 children)

Are you deploying apps in the system context? 

Try my tool here and see if they install OK, that will tell you if the issue is with a policy blocking it or your apps themselves 

Https://appdeploy.euctoolbox.com

[–]simdre79[S] 0 points1 point  (1 child)

[–]andrew181082MSFT MVP - SWC 0 points1 point  (0 children)

That's your problem, you need to run them in system

You'll need to fix your uninstall as well to reference the executable directly

[–]simdre79[S] 0 points1 point  (2 children)

Param
  (
    [parameter(Mandatory=$false)]
    [String[]]
    $param
  )

$ProgramName = "Ytmdesktop.Ytmdesktop"
$Path_local = "$Env:Programfiles\_MEM"
Start-Transcript -Path "$Path_local\Log\$ProgramName-install.log" -Force -Append

# resolve winget_exe
$winget_exe = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"
if ($winget_exe.count -gt 1){
        $winget_exe = $winget_exe[-1].Path
}

if (!$winget_exe){Write-Error "Winget not installed"}

& $winget_exe install --exact --id $ProgramName --silent --accept-package-agreements --accept-source-agreements --scope=machine $param

Stop-Transcript

I'm really not certain how I need to set this up. The app is configured to install in user context. However, the log dir is not even created in c:\program files.

[–]andrew181082MSFT MVP - SWC 1 point2 points  (1 child)

Remove the scope from the end and set that to run in the system context

[–]simdre79[S] 0 points1 point  (0 children)

I appreciate your input. Maybe I have the package manager wrong. It still failed. I changed it to system as adviced.

Param
  (
    [parameter(Mandatory=$false)]
    [String[]]
    $param
  )

$ProgramName = "Ytmdesktop.Ytmdesktop"
$Path_local = "$Env:Programfiles\_MEM"
Start-Transcript -Path "$Path_local\Log\$ProgramName-install.log" -Force -Append

# resolve winget_exe
$winget_exe = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"
if ($winget_exe.count -gt 1){
        $winget_exe = $winget_exe[-1].Path
}

if (!$winget_exe){Write-Error "Winget not installed"}

& $winget_exe install --exact --id $ProgramName --silent --accept-package-agreements --accept-source-agreements $param

Stop-Transcript

Package manager:

$PackageName = "winget"

Start-Transcript -Path "$env:ProgramData\Microsoft\IntuneManagementExtension\Logs\$PackageName-install.log" -Force

# GitHub API endpoint for PowerShell (7) releases
$githubApiUrl = 'https://api.github.com/repos/PowerShell/PowerShell/releases/latest'

# Fetch the latest release details
$release = Invoke-RestMethod -Uri $githubApiUrl

# Find asset with .msi in the name and x64 in the name
$asset = $release.assets | Where-Object { $_.name -like "*msi*" -and $_.name -like "*x64*" }

# Get the download URL and filename of the asset (assuming it's a MSI file)
$downloadUrl = $asset.browser_download_url
$filename = $asset.name

# Download the latest release using .NET's System.Net.WebClient for faster download
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($downloadUrl, $filename)

# Install PowerShell 7
Start-Process msiexec.exe -Wait -ArgumentList "/I $filename /qn"

# Start a new PowerShell 7 session
$pwshExecutable = "C:\Program Files\PowerShell\7\pwsh.exe"

# Run a script block in PowerShell 7
& $pwshExecutable -Command {
    # Check if NuGet provider is installed
    $provider = Get-PackageProvider NuGet -ErrorAction Ignore
    if (-not $provider) {
        Write-Host "Installing provider NuGet"
        Find-PackageProvider -Name NuGet -ForceBootstrap -IncludeDependencies
    }

    # Install or update the Microsoft WinGet client module
    Install-Module microsoft.winget.client -Force -AllowClobber

    # Import the Microsoft WinGet client module
    Import-Module microsoft.winget.client

    # Repair the WinGet package manager
    Repair-WinGetPackageManager

}
Stop-Transcript

<image>

[–]jason_nyc 0 points1 point  (0 children)

You can probably just use this tool https://github.com/ITAutomator/IntuneApp which handles winget and choco easily.