Forum Discussion
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-AppxPackage" command. For some Intune showed me that the script had failed but it still was installed and I could use winget.
After that, I created a new script to install VC redist with winget but it failed. In logs, I found the error message and it says that the term "winget" is not recognized as the name of the cmdlet.
Has someone an idea what the problem is?
- Depends on how you install the app... i am going to assume it is delivered from the system context
Take a look at this website as it provides the powershell script you need. As you need to define the path to the winget executable... otherwise you will get the error you mentioned
https://call4cloud.nl/2021/05/cloudy-with-a-chance-of-winget/#part3 - Deleted
Hello 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! 🙂
- Mmm... 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