azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Invoke-AzVMRunCommand for powershell removes caret character

Open rezarms opened this issue 2 years ago • 5 comments

Description

invoke-azcommand removes caret character . I tried to call invoke-azcommand to run a powershell script but my script receives parameter with deleted caret character.

$password="test^123456"

Invoke-AzVMRunCommand -ResourceGroupName $rg -VMName $vm -CommandId 'RunPowerShellScript' -ScriptPath './test.ps1' -Parameter @{"password"=$password}

in my script I print out the value of the parameter which is "test123456"

Issue script & Debug output

HTTP Method:
POST

Absolute Uri:
https://management.azure.com/subscriptions/000000000000000/resourceGroups/rg1/providers/Microsoft.Compute/virtualMachines/vm1/runCommand?api
-version=2020-12-01

Headers:
x-ms-client-request-id        : 00000000000000000000
accept-language               : en-US

Body:
{
  "commandId": "RunPowerShellScript",
  "script": [
    "[cmdletbinding(SupportsShouldProcess=$true)]",
    " param(",
    " [parameter(Mandatory=$true)][String]$password)",
    " write-host \" password is $password\""
  ],
  "parameters": [
    {
      "name": "password",
      "value": "test^123456"
    }
  ]
}


DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
Accepted



Body:
{
  "value": [
    {
      "code": "ComponentStatus/StdOut/succeeded",
      "level": "Info",
      "displayStatus": "Provisioning succeeded",
      "message": " password is test123456"
    },
    {
      "code": "ComponentStatus/StdErr/succeeded",
      "level": "Info",
      "displayStatus": "Provisioning succeeded",
      "message": ""
    }
  ]
}

Environment data

Name                           Value                                                                                                                                                 
----                           -----                                                                                                                                                 
PSVersion                      5.1.19041.1682                                                                                                                                        
PSEdition                      Desktop                                                                                                                                               
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                               
BuildVersion                   10.0.19041.1682                                                                                                                                       
CLRVersion                     4.0.30319.42000                                                                                                                                       
WSManStackVersion              3.0                                                                                                                                                   
PSRemotingProtocolVersion      2.3                                                                                                                                                   
SerializationVersion           1.1.0.1

Module versions

Script     2.3.0      Az.Accounts                        
Script     4.13.0     Az.Compute                                      
Script     3.4.4      Az.KeyVault

Error output

No response

rezarms avatar Jul 28 '22 12:07 rezarms

Thank you for your feedback. This has been routed to the support team for assistance.

msftbot[bot] avatar Jul 29 '22 06:07 msftbot[bot]

@rezarms We are looking into it and get back to you for any additional information.

SaurabhSharma-MSFT avatar Jul 29 '22 16:07 SaurabhSharma-MSFT

@rezarms I am able to reproduce this and looks like issue at service end. I am checking internally on this issue and get back to you.

SaurabhSharma-MSFT avatar Jul 29 '22 21:07 SaurabhSharma-MSFT

It seems other special characters would cause different issue. For example < character would fail script call.

rezarms avatar Jul 29 '22 22:07 rezarms

@rezarms This seems to be a limitation on command prompt on VM and the product team is working to provide a fix for the caret character. I will update you as soon as it is available in production. Thanks.

SaurabhSharma-MSFT avatar Aug 29 '22 19:08 SaurabhSharma-MSFT

A similar behavior happens here with the "&" in a paremeter string. This causes that the parameter is empty all at once.

It is really a strange behavior. Is there any feedback on this at some point?

My environment: Windows 11 Script 2.13.1 Az.Accounts
Script 5.7.1 Az.Compute
PSVersion 7.3.8 PSEdition Core

superfliege avatar Oct 20 '23 13:10 superfliege