Forum Discussion
egor1893
Dec 06, 2023Copper Contributor
App installation with PowerShell and winget
Hello, I'm trying to install a Visual C++ Redistributable package with winget. The first problem I had was that "App Installer" wasn't installed on the devices so I installed it via the "Add-AppxPac...
Deleted
Dec 09, 2023Hello egor1893
Welcome to the Microsoft community, my name is Recep I'll be happy to help you today.
Here are a few steps you can take to troubleshoot and potentially resolve the issue:
- Specify Full Path to Winget: Instead of just using "winget" in your script, specify the full path to the winget executable. You can find the path by running the following command in PowerShell:
Update your script to use the full path, for example:
& "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.11.10902.0_x64__8wekyb3d8bbwe\AppInstaller.exe" install --source "Microsoft.VisualStudio.VCRedist.140" -a
Ensure that you have the correct path based on the output of the Get-Command cmdlet.
- Check Execution Policy: Ensure that the PowerShell execution policy allows the script to run. You can set it to bypass for testing purposes:
Add this line at the beginning of your script and see if it resolves the issue.
- Run PowerShell in 64-bit: Some applications, including winget, may require a 64-bit PowerShell session. If you are using a 32-bit PowerShell session, switch to a 64-bit session.
Run this command to launch a 64-bit PowerShell session:
Then try running your script again.
- Logging and Error Handling: Add detailed logging and error handling to your script. This can help you identify where the script is failing. For example:
If I have answered your question, please mark your post as Solved If you like my response, please give it a Like Appreciate your Kudos! Proud to contribute! 🙂 |
- Dec 09, 2023Mmm... specifying the full path in the script wont be a good idea as with the next winget update your scripts are not going to work anymore...
just like i mentioned in my reply and linking to the blog which mentions this code:
$ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"
if ($ResolveWingetPath){
$WingetPath = $ResolveWingetPath[-1].Path
}
$Wingetpath = Split-Path -Path $WingetPath -Parent
cd $wingetpath
.\winget.exe install --exact --id Microsoft.EdgeWebView2Runtime --silent --accept-package-agreements --accept-source-agreements