I have several VMs in Azure where I want to update all applications using winget upgrade. The VMs are running Windows Server 2016/2022, and I have manually installed winget on them. When I log into the machines, I can execute winget commands without any issues.
However, I wanted to run winget upgrade using Invoke-AzVMRunCommand, but I keep getting the following message and nothing happens:
Value[0] :
Code : ComponentStatus/StdOut/succeeded
Level : Info
DisplayStatus : Provisioning succeeded
Message :
Value[1] :
Code : ComponentStatus/StdErr/succeeded
Level : Info
DisplayStatus : Provisioning succeeded
Message :
Status : Succeeded
Capacity : 0
Count : 0
I also tried installing a single app with winget or writing the output to a file using -o, but the file remains empty and nothing gets installed.
Invoke-AzVMRunCommand -ResourceGroupName $rgName -VMName $vmName -CommandId 'RunPowerShellScript' -ScriptString 'winget install Microsoft.Azure.StorageExplorer'
Even when querying the version, I get the same successful message back.
Invoke-AzVMRunCommand -ResourceGroupName $rgName -VMName $vmName -CommandId 'RunPowerShellScript' -ScriptString 'winget --version'
I am the VM Owner and VM Contributor on the machines.
Can anyone help me?
I expect that my script will work and that I will be able to automatically update all applications on the VMs.
I believe I have found the problem. When I call a script in Invoke-AzVmRunCommand, it is automatically executed in the system context with the System user. However, in the system context, you cannot run winget by default because it is an MSIX package. There are some workarounds available, but they are quite cumbersome and none of them have worked so far.I think I’ll close the ticket.