Azure / Azure/azure-powershell
Invoke-AzureRmVMRunCommand and spaces in parameters
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### Description
When running `Invoke-AzureRmVMRunCommand`, if the `-Parameter` hash table contains values with embedded spaces, only the part of said values left of the first space seem to be taken into account.
### Script/Steps for Reproduction
1. Create a local script (`dummy_script.ps1`) with the following:
```powershell
param(
[String]$yourname
)
"Hello $yourname!" >C:\blah.log
```
2. Create a test VM (the one used here runs Windows Server 2012 R2, in case that's relevant)
3. Run this command:
```powershell
Invoke-AzureRmVMRunCommand -ResourceGroupName "$YourResourceGroupName" -VMName "YourVMName" -CommandId "RunPowerShellScript" -ScriptPath "dummy_script.ps1" -Parameter @{"yourname" = "Max Mustermann The Fifth"} -Verbose
```
#### Expected contents of `C:\blah.log` in the VM:
`Hello Max Mustermann The Fifth!`
#### Actual contents of that file:
`Hello Max!`
### Module Version
```powershell
Get-Module -ListAvailable
Directory: /usr/local/share/powershell/Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 0.13.1 Azure.AnalysisServices.Netcore {Add-AzureAnalysisServicesAccount, Restart-AzureAnalysisServicesInstance, Export-AzureAnalysisServicesInstanceLog, Sync-AzureAnalysisServicesInstance}
Script 0.13.1 Azure.Storage.Netcore {Get-AzureStorageTable, New-AzureStorageTableSASToken, New-AzureStorageTableStoredAccessPolicy, New-AzureStorageTable...}
Script 0.13.1 AzureRM.Aks.Netcore {Get-AzureRmAks, New-AzureRmAks, Remove-AzureRmAks, Import-AzureRmAksCredential...}
Script 0.13.1 AzureRM.AnalysisServices.Netcore {Resume-AzureRmAnalysisServicesServer, Suspend-AzureRmAnalysisServicesServer, Get-AzureRmAnalysisServicesServer, Remove-AzureRmAnalysisServicesServer...}
Script 0.13.1 AzureRM.ApiManagement.Netcore {Add-AzureRmApiManagementRegion, Get-AzureRmApiManagementSsoToken, New-AzureRmApiManagementHostnameConfiguration, New-AzureRmApiManagementCustomHostnameConfiguration...}
Script 0.13.1 AzureRM.ApplicationInsights.Netcore {Get-AzureRmApplicationInsights, New-AzureRmApplicationInsights, Remove-AzureRmApplicationInsights, Set-AzureRmApplicationInsightsPricingPlan...}
Script 0.13.1 AzureRM.Automation.Netcore {Get-AzureRMAutomationHybridWorkerGroup, Get-AzureRmAutomationJobOutputRecord, Import-AzureRmAutomationDscNodeConfiguration, Export-AzureRmAutomationDscConfiguration...}
Script 0.13.1 AzureRM.Batch.Netcore {Remove-AzureRmBatchAccount, Get-AzureRmBatchAccount, Get-AzureRmBatchAccountKeys, New-AzureRmBatchAccount...}
Script 0.13.1 AzureRM.Billing.Netcore {Get-AzureRmBillingInvoice, Get-AzureRmBillingPeriod, Get-AzureRmEnrollmentAccount}
Script 0.13.1 AzureRM.Cdn.Netcore {Get-AzureRmCdnProfile, Get-AzureRmCdnProfileSsoUrl, New-AzureRmCdnProfile, Remove-AzureRmCdnProfile...}
Script 0.13.1 AzureRM.CognitiveServices.Netcore {Get-AzureRmCognitiveServicesAccount, Get-AzureRmCognitiveServicesAccountKey, Get-AzureRmCognitiveServicesAccountSkus, Get-AzureRmCognitiveServicesAccountUsage...}
Script 0.13.1 AzureRM.Compute.Netcore {Remove-AzureRmAvailabilitySet, Get-AzureRmAvailabilitySet, New-AzureRmAvailabilitySet, Update-AzureRmAvailabilitySet...}
Script 0.13.1 AzureRM.Consumption.Netcore {Get-AzureRmConsumptionBudget, Get-AzureRmConsumptionMarketplace, Get-AzureRmConsumptionPriceSheet, Get-AzureRmConsumptionReservationDetail...}
Script 0.13.1 AzureRM.ContainerInstance.Netcore {New-AzureRmContainerGroup, Get-AzureRmContainerGroup, Remove-AzureRmContainerGroup, Get-AzureRmContainerInstanceLog}
Script 0.13.1 AzureRM.ContainerRegistry.Netcore {New-AzureRmContainerRegistry, Get-AzureRmContainerRegistry, Update-AzureRmContainerRegistry, Remove-AzureRmContainerRegistry...}
Script 0.13.1 AzureRM.DataLakeAnalytics.Netcore {Get-AzureRmDataLakeAnalyticsDataSource, New-AzureRmDataLakeAnalyticsCatalogCredential, Remove-AzureRmDataLakeAnalyticsCatalogCredential, Remove-AzureRmDataLakeAnalyticsCatalogSecret...}
Script 0.13.1 AzureRM.DataLakeStore.Netcore {Get-AzureRmDataLakeStoreTrustedIdProvider, Remove-AzureRmDataLakeStoreTrustedIdProvider, Remove-AzureRmDataLakeStoreFirewallRule, Set-AzureRmDataLakeStoreTrustedIdProvider...}
Script 0.13.1 AzureRM.DevTestLabs.Netcore {Get-AzureRmDtlAllowedVMSizesPolicy, Get-AzureRmDtlAutoShutdownPolicy, Get-AzureRmDtlAutoStartPolicy, Get-AzureRmDtlVMsPerLabPolicy...}
Script 0.13.1 AzureRM.Dns.Netcore {Get-AzureRmDnsRecordSet, New-AzureRmDnsRecordConfig, Remove-AzureRmDnsRecordSet, Set-AzureRmDnsRecordSet...}
Script 0.13.1 AzureRM.EventGrid.Netcore {New-AzureRmEventGridTopic, Get-AzureRmEventGridTopic, Set-AzureRmEventGridTopic, New-AzureRmEventGridTopicKey...}
Script 0.13.1 AzureRM.EventHub.Netcore {New-AzureRmEventHubNamespace, Get-AzureRmEventHubNamespace, Set-AzureRmEventHubNamespace, Remove-AzureRmEventHubNamespace...}
Script 0.13.1 AzureRM.Insights.Netcore {Get-AzureRmMetricDefinition, Get-AzureRmMetric, Remove-AzureRmLogProfile, Get-AzureRmLogProfile...}
Script 0.13.1 AzureRM.IotHub.Netcore {Add-AzureRmIotHubKey, Get-AzureRmIotHubEventHubConsumerGroup, Get-AzureRmIotHubConnectionString, Get-AzureRmIotHubJob...}
Script 0.13.1 AzureRM.KeyVault.Netcore {Add-AzureKeyVaultCertificate, Update-AzureKeyVaultCertificate, Stop-AzureKeyVaultCertificateOperation, Get-AzureKeyVaultCertificateOperation...}
Script 0.13.1 AzureRM.LogicApp.Netcore {Get-AzureRmIntegrationAccountAgreement, Get-AzureRmIntegrationAccountCallbackUrl, Get-AzureRmIntegrationAccountCertificate, Get-AzureRmIntegrationAccount...}
Script 0.13.1 AzureRM.MachineLearning.Netcore {Move-AzureRmMlCommitmentAssociation, Get-AzureRmMlCommitmentAssociation, Get-AzureRmMlCommitmentPlanUsageHistory, Remove-AzureRmMlCommitmentPlan...}
Script 0.13.1 AzureRM.MachineLearningCompute.N... {Get-AzureRmMlOpCluster, Get-AzureRmMlOpClusterKey, Test-AzureRmMlOpClusterSystemServicesUpdateAvailability, Update-AzureRmMlOpClusterSystemService...}
Script 0.13.1 AzureRM.MarketplaceOrdering.Netcore {Get-AzureRmMarketplaceTerms, Set-AzureRmMarketplaceTerms}
Script 0.13.1 AzureRM.Media.Netcore {Sync-AzureRmMediaServiceStorageKeys, Set-AzureRmMediaServiceKey, Get-AzureRmMediaServiceKeys, Get-AzureRmMediaServiceNameAvailability...}
Script 0.13.1 AzureRM.Netcore
Script 0.13.1 AzureRM.Network.Netcore {Add-AzureRmApplicationGatewayAuthenticationCertificate, Get-AzureRmApplicationGatewayAuthenticationCertificate, New-AzureRmApplicationGatewayAuthenticationCertificate, Remove-AzureRmApplicationGatewayAuthenticationCertificate...}
Script 0.13.1 AzureRM.NotificationHubs.Netcore {Get-AzureRmNotificationHub, Get-AzureRmNotificationHubAuthorizationRules, Get-AzureRmNotificationHubListKeys, Get-AzureRmNotificationHubPNSCredentials...}
Script 0.13.1 AzureRM.OperationalInsights.Netcore {New-AzureRmOperationalInsightsAzureActivityLogDataSource, New-AzureRmOperationalInsightsCustomLogDataSource, Disable-AzureRmOperationalInsightsLinuxCustomLogCollection, Disable-AzureRmOperationalInsightsIISLogCollection...}
Script 0.13.1 AzureRM.PolicyInsights.Netcore {Get-AzureRmPolicyEvent, Get-AzureRmPolicyState, Get-AzureRmPolicyStateSummary}
Script 0.13.1 AzureRM.PowerBIEmbedded.Netcore {Remove-AzureRmPowerBIWorkspaceCollection, Get-AzureRmPowerBIWorkspaceCollection, Get-AzureRmPowerBIWorkspaceCollectionAccessKeys, Get-AzureRmPowerBIWorkspace...}
Script 0.13.1 AzureRM.Profile.Netcore {Disable-AzureRmDataCollection, Disable-AzureRmContextAutosave, Enable-AzureRmDataCollection, Enable-AzureRmContextAutosave...}
Script 0.13.1 AzureRM.Relay.Netcore {New-AzureRmRelayNamespace, Get-AzureRmRelayNamespace, Set-AzureRmRelayNamespace, Remove-AzureRmRelayNamespace...}
Script 0.13.1 AzureRM.Resources.Netcore {Get-AzureRmProviderOperation, Remove-AzureRmRoleAssignment, Get-AzureRmRoleAssignment, New-AzureRmRoleAssignment...}
Script 0.13.1 AzureRM.ServiceBus.Netcore {New-AzureRmServiceBusNamespace, Get-AzureRmServiceBusNamespace, Set-AzureRmServiceBusNamespace, Remove-AzureRmServiceBusNamespace...}
Script 0.13.1 AzureRM.ServiceFabric.Netcore {Add-AzureRmServiceFabricApplicationCertificate, Add-AzureRmServiceFabricClientCertificate, Add-AzureRmServiceFabricClusterCertificate, Add-AzureRmServiceFabricNode...}
Script 0.13.1 AzureRM.Sql.Netcore {Get-AzureRmSqlDatabaseTransparentDataEncryption, Get-AzureRmSqlDatabaseTransparentDataEncryptionActivity, Set-AzureRmSqlDatabaseTransparentDataEncryption, Get-AzureRmSqlDatabaseUpgradeHint...}
Script 0.13.1 AzureRM.Storage.Netcore {Get-AzureRmStorageAccount, Get-AzureRmStorageAccountKey, New-AzureRmStorageAccount, New-AzureRmStorageAccountKey...}
Script 0.13.1 AzureRM.StreamAnalytics.Netcore {Get-AzureRmStreamAnalyticsFunction, Get-AzureRmStreamAnalyticsDefaultFunctionDefinition, New-AzureRmStreamAnalyticsFunction, Remove-AzureRmStreamAnalyticsFunction...}
Script 0.13.1 AzureRM.Tags.Netcore {Remove-AzureRmTag, Get-AzureRmTag, New-AzureRmTag}
Script 0.13.1 AzureRM.TrafficManager.Netcore {Disable-AzureRmTrafficManagerEndpoint, Enable-AzureRmTrafficManagerEndpoint, Set-AzureRmTrafficManagerEndpoint, Get-AzureRmTrafficManagerEndpoint...}
Script 0.13.1 AzureRM.UsageAggregates.Netcore Get-UsageAggregates
Script 0.13.1 AzureRM.Websites.Netcore {Get-AzureRmAppServicePlan, Set-AzureRmAppServicePlan, New-AzureRmAppServicePlan, Remove-AzureRmAppServicePlan...}
Directory: /opt/microsoft/powershell/6.0.4/Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 1.1.0.0 Microsoft.PowerShell.Archive {Compress-Archive, Expand-Archive}
Manifest 3.0.0.0 Microsoft.PowerShell.Host {Start-Transcript, Stop-Transcript}
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path...}
Manifest 3.0.0.0 Microsoft.PowerShell.Security {Get-Credential, Get-ExecutionPolicy, Set-ExecutionPolicy, ConvertFrom-SecureString...}
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Format-List, Format-Custom, Format-Table, Format-Wide...}
Script 1.1.7.0 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}
Script 1.6.0 PowerShellGet {Install-Module, Find-Module, Save-Module, Update-Module...}
Script 0.0 PSDesiredStateConfiguration {Get-MofInstanceName, ValidateNodeManager, Get-InnerMostErrorRecord, Update-ConfigurationErrorCount...}
Script 1.2 PSReadLine {Get-PSReadlineKeyHandler, Set-PSReadlineKeyHandler, Remove-PSReadlineKeyHandler, Get-PSReadlineOption...}
```
### Environment Data
```powershell
$PSVersionTable
Name Value
---- -----
PSVersion 6.0.4
PSEdition Core
GitCommitId v6.0.4
OS Linux 4.16.0-0.bpo.1-amd64 #1 SMP Debian 4.16.5-1~bpo9+1 (2018-05-06)
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```
### Debug Output
```
Invoke-AzureRmVMRunCommand -ResourceGroupName "Test_rg" -VMName "TestVM" -CommandId "RunPowerShellScript" -ScriptPath "dummy_script.ps1" -Parameter @{"yourname" = "Max Mustermann The Fifth"} -Verbose
DEBUG: 12:25:51 - InvokeAzureRmVMRunCommand begin processing with ParameterSet 'DefaultParameter'.
DEBUG: 12:25:51 - using account id 'foo.bar@email.com'...
VERBOSE: Performing the operation "Invoke" on target "TestVM".
DEBUG: [Common.Authentication]: Authenticating using Account: 'foo.bar@email.com', environment: 'AzureCloud', tenant: '37451347-e8d2-4458-8077-8cceaab08380'
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
POST
Absolute Uri:
https://management.azure.com/subscriptions/a8c043c7-88dc-4a14-8c75-0387d1f45cc0/resourceGroups/Test_rg/providers/Microsoft.Compute/virtualMachines/TestVM/runCommand?api-version=2018-04-01
Headers:
x-ms-client-request-id : 20f63285-ca8a-4759-a3bf-c8dd4f79f038
accept-language : en-US
Body:
{
"commandId": "RunPowerShellScript",
"script": [
"param(",
" [String]$yourname",
" )",
"\"Hello $yourname!\" >C:\\blah.log"
],
"parameters": [
{
"name": "yourname",
"value": "Max Mustermann The Fifth"
}
]
}
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
Accepted
Headers:
Cache-Control : no-cache
Pragma : no-cache
Location : https://management.azure.com/subscriptions/a8c043c7-88dc-4a14-8c75-0387d1f45cc0/providers/Microsoft.Compute/locations/ukwest/operations/6583ef05-d951-43b3-bb8b-d0b5428e3c4c?monitor=true&api-version=2018-04-01
Azure-AsyncOperation : https://management.azure.com/subscriptions/a8c043c7-88dc-4a14-8c75-0387d1f45cc0/providers/Microsoft.Compute/locations/ukwest/operations/6583ef05-d951-43b3-bb8b-d0b5428e3c4c?api-version=2018-04-01
x-ms-ratelimit-remaining-resource: Microsoft.Compute/UpdateVM3Min;239,Microsoft.Compute/UpdateVM30Min;1195
Strict-Transport-Security : max-age=31536000; includeSubDomains
x-ms-served-by : 31fa4520-3ace-413b-9767-4c034cc33923_131781507814555981
x-ms-request-id : 6583ef05-d951-43b3-bb8b-d0b5428e3c4c
Server : Microsoft-HTTPAPI/2.0,Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-writes: 1198
x-ms-correlation-request-id : bf3d1bfd-905d-493f-a0c0-2b374b2f4775
x-ms-routing-request-id : UKNORTH:20180917T122559Z:bf3d1bfd-905d-493f-a0c0-2b374b2f4775
X-Content-Type-Options : nosniff
Date : Mon, 17 Sep 2018 12:25:59 GMT
Body:
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions/a8c043c7-88dc-4a14-8c75-0387d1f45cc0/providers/Microsoft.Compute/locations/ukwest/operations/6583ef05-d951-43b3-bb8b-d0b5428e3c4c?api-version=2018-04-01
Headers:
Body:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
OK
Headers:
Cache-Control : no-cache
Pragma : no-cache
x-ms-ratelimit-remaining-resource: Microsoft.Compute/GetOperation3Min;14998,Microsoft.Compute/GetOperation30Min;29982
Strict-Transport-Security : max-age=31536000; includeSubDomains
x-ms-served-by : 31fa4520-3ace-413b-9767-4c034cc33923_131781507814555981
x-ms-request-id : a0ce9b65-95fc-4eac-8262-853b79e87b42
Server : Microsoft-HTTPAPI/2.0,Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-reads: 11996
x-ms-correlation-request-id : dd50410b-bd71-4bb7-be38-f2e653c132d8
x-ms-routing-request-id : UKNORTH:20180917T122630Z:dd50410b-bd71-4bb7-be38-f2e653c132d8
X-Content-Type-Options : nosniff
Date : Mon, 17 Sep 2018 12:26:29 GMT
Body:
{
"startTime": "2018-09-17T12:25:59.8512565+00:00",
"endTime": "2018-09-17T12:26:13.6689291+00:00",
"status": "Succeeded",
"properties": {
"output": {
"value": [
{
"code": "ComponentStatus/StdOut/succeeded",
"level": "Info",
"displayStatus": "Provisioning succeeded",
"message": ""
},
{
"code": "ComponentStatus/StdErr/succeeded",
"level": "Info",
"displayStatus": "Provisioning succeeded",
"message": ""
}
]
}
},
"name": "6583ef05-d951-43b3-bb8b-d0b5428e3c4c"
}
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions/a8c043c7-88dc-4a14-8c75-0387d1f45cc0/providers/Microsoft.Compute/locations/ukwest/operations/6583ef05-d951-43b3-bb8b-d0b5428e3c4c?monitor=true&api-version=2018-04-01
Headers:
Body:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
OK
Headers:
Cache-Control : no-cache
Pragma : no-cache
x-ms-ratelimit-remaining-resource: Microsoft.Compute/GetOperation3Min;14997,Microsoft.Compute/GetOperation30Min;29981
Strict-Transport-Security : max-age=31536000; includeSubDomains
x-ms-served-by : 31fa4520-3ace-413b-9767-4c034cc33923_131781507814555981
x-ms-request-id : 14c4bba8-2be3-4216-a12e-8d05d33dc1b3
Server : Microsoft-HTTPAPI/2.0,Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-reads: 11995
x-ms-correlation-request-id : 96c12d9b-ea69-460f-9037-ff97cf82f1a8
x-ms-routing-request-id : UKNORTH:20180917T122630Z:96c12d9b-ea69-460f-9037-ff97cf82f1a8
X-Content-Type-Options : nosniff
Date : Mon, 17 Sep 2018 12:26:29 GMT
Body:
{
"value": [
{
"code": "ComponentStatus/StdOut/succeeded",
"level": "Info",
"displayStatus": "Provisioning succeeded",
"message": ""
},
{
"code": "ComponentStatus/StdErr/succeeded",
"level": "Info",
"displayStatus": "Provisioning succeeded",
"message": ""
}
]
}
DEBUG: AzureQoSEvent: CommandName - Invoke-AzureRmVMRunCommand; IsSuccess - True; Duration - 00:00:38.5808246; Exception - ;
DEBUG: Finish sending metric.
DEBUG: 12:26:38 - InvokeAzureRmVMRunCommand end processing.
DEBUG: 12:26:38 - InvokeAzureRmVMRunCommand end processing.
```
Is this a bug, or have I missed something? I have naively tried escaping the spaces with backslashes, which led to the backslashes themselves being output in the target file as well without solving the issue.
Contributor guide
Assessment
This issue has not been assessed yet.