while trying to run the az run command with the powershell script but facing an error

Vedanth Pulipati 241 Reputation points
2022-05-11T07:50:49.117+00:00

i am trying to run the below az run command but facing the error

command :

az vm run-command invoke --command-id RunPowerShellScript -g "XXXXXX" -n "XXXX" --scripts "winrm set winrm/config/service/auth '@{Kerberos="true"}'"

error:
200865-image.png

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,085 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,083 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,355 questions
0 comments No comments
{count} votes

Accepted answer
  1. deherman-MSFT 33,141 Reputation points Microsoft Employee
    2022-05-11T19:42:31.313+00:00

    @Vedanth Pulipati

    I understand you are trying to use RunPowerShellScript from azure CLI but it is failing.

    I believe the issue is with the quotations inside your script. You can see Quoting issues with PowerShell page for more explicit info. I was able to run the command via Portal without issue.
    201146-image.png

    You don't need to worry about escaping characters if running the script from a file.
    201175-image.png

    Please give this a try to see if it works for you. Let me know if you are still running into issues.

    -------------------------------

    Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. K. J. Skinner 181 Reputation points
    2022-05-12T03:33:04.33+00:00

    Hi @Vedanth Pulipati ! @deherman-MSFT is right that it is the quotes that is probably giving you issues. Both of his solutions should work, but if you need to have it in inline on your PowerShell, its the double-quotes (") specifically causing problems and you can escape them in PowerShell by doubling up on your double-quotes (""):

    az vm run-command invoke --command-id RunPowerShellScript -g "XXXXXX" -n "XXXX" --scripts "winrm set winrm/config/service/auth '@{Kerberos=""true""}'"  
    
    2 people found this answer helpful.
    0 comments No comments