az vm run-command invoke installing software on azure virtual machine command fails

Viewed 48

I have got an arm template successfully provisioning azure virtual machines, post provisioning I will require some packages to be installed on the virtual machine. The way I am currently doing this right now is via the following commands.

Set-AzVMCustomScriptExtension -ResourceGroupName "xxx" -VMName "xx" -Name "ChocoInstall" -FileUri "https://community.chocolatey.org/install.ps1" ` -Run "install.ps1" -Location "xx"

once chocolatey is installed, the next step is to install some packages.

I found a similar answer here and I am trying to use thesame command.

az vm run-command invoke -g "xxx"  -n "xx" --command-id RunpowerShellScript --scripts "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" ; "choco install notepadplusplus"

I then get the error below.

"code": "ComponentStatus/StdErr/succeeded", "displayStatus": "Provisioning succeeded", "level": "Info", "message": "choco : The term 'choco' is not recognized as the name of a cmdlet, function, script file, or operable program. Check \nthe spelling of the name, or if a path was included, verify that the path is correct and try again.\nAt C:\\Packages\\Plugins\\Microsoft.CPlat.Core.RunCommandWindows\\1.1.11\\Downloads\\script2.ps1:3 char:1\n+ choco install notepadplusplus\n+ ~~~~~\n + CategoryInfo : ObjectNotFound: (choco:String) [], CommandNotFoundException\n + FullyQualifiedErrorId : CommandNotFoundException\n ", "time": null } ] }

1 Answers

I have reproduced in my environment and i got succeeded in that, I followed Microsoft-Document and M QandA ,below is the commmand I used and i got expected results as below:

 az vm run-command invoke -g MyResourceGroup  -n MyVm --command-id RunpowerShellScript  --scripts "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"  ;  "choco install -y python3"

enter image description here

Try choco install -y, if that doesnt work try chocolatey install -y

Example: Installing nginx in linux Vm:

az vm run-command invoke -g MyResourceGroup -n MyVm --command-id RunShellScript --scripts "sudo apt-get update && sudo apt-get install -y nginx"

enter image description here

Related