Skip to content

Commit 379c269

Browse files
authored
Merge pull request #216491 from ericd-mst-github/erd-run-command-windows
Erd run command windows
2 parents 4de6558 + 639df71 commit 379c269

File tree

4 files changed

+227
-43
lines changed

4 files changed

+227
-43
lines changed

articles/virtual-machines/TOC.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,9 +880,9 @@
880880
href: ./linux/run-command.md
881881
- name: Action Run Commands for Windows
882882
href: ./windows/run-command.md
883-
- name: Managed Run Commands for Linux (preview)
883+
- name: Managed Run Commands for Linux
884884
href: ./linux/run-command-managed.md
885-
- name: Managed Run Commands for Windows (preview)
885+
- name: Managed Run Commands for Windows
886886
href: ./windows/run-command-managed.md
887887
- name: Extensions
888888
items:

articles/virtual-machines/linux/run-command-managed.md

Lines changed: 106 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,32 @@
11
---
2-
title: Run scripts in a Linux VM in Azure using managed Run Commands (preview)
2+
title: Run scripts in a Linux VM in Azure using managed Run Commands
33
description: This topic describes how to run scripts within an Azure Linux virtual machine by using the updated managed Run Command feature.
44
services: automation
55
ms.service: virtual-machines
66
ms.collection: linux
77
author: nikhilpatel909
88
ms.author: erd
9-
ms.date: 09/08/2022
9+
ms.date: 10/31/2022
1010
ms.topic: how-to
1111
ms.reviewer: erd
1212
ms.custom: devx-track-azurepowershell, devx-track-azurecli
1313
---
14-
# Preview: Run scripts in your Linux VM by using managed Run Commands
14+
# Run scripts in your Linux VM by using managed Run Commands
1515

1616
**Applies to:** :heavy_check_mark: Linux VMs :heavy_check_mark: Flexible scale sets
1717

18-
> [!IMPORTANT]
19-
> **Managed Run Command** is currently in public preview.
20-
> This preview version is provided without a service-level agreement, and we don't recommend it for production workloads. Certain features might not be supported or might have constrained capabilities.
21-
> For more information, see [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
2218

2319
The Run Command feature uses the virtual machine (VM) agent to run scripts within an Azure Linux VM. You can use these scripts for general machine or application management. They can help you quickly diagnose and remediate VM access and network issues and get the VM back to a good state.
2420

2521
The *updated* managed Run Command uses the same VM agent channel to execute scripts and provides the following enhancements over the [original action oriented Run Command](run-command.md):
2622
- Support for updated Run Command through ARM deployment template
2723
- Parallel execution of multiple scripts
28-
- Sequential execution of scripts
29-
- RunCommand script can be canceled
24+
- Sequential execution of scripts
3025
- User specified script timeout
3126
- Support for long running (hours/days) scripts
3227
- Passing secrets (parameters, passwords) in a secure manner
3328

3429

35-
## Register for preview
36-
37-
You must register your subscription in order to use managed Run Command during public preview. Go to [set up preview features in Azure subscription](../../azure-resource-manager/management/preview-features.md) for registration instructions and use the feature name `RunCommandPreview`.
38-
3930
## Azure CLI
4031

4132
The following examples use [az vm run-command](/cli/azure/vm/run-command) to run shell script on an Azure Linux VM.
@@ -61,6 +52,10 @@ This command will retrieve current execution progress, including latest output,
6152
az vm run-command show --name "myRunCommand" --vm-name "myVM" --resource-group "myRG" --expand instanceView
6253
```
6354

55+
> [!Note]
56+
> Output and error fields in `instanceView` is limited to last 4KB.
57+
> If you'd like to access the full output and error, you have the option of forwarding the output and error data to storage append blobs using `-outputBlobUri` and `-errorBlobUri` parameters while executing Run Command using `Set-AzVMRunCommand` or `Set-AzVMssRunCommand`.
58+
6459
### Delete RunCommand resource from the VM
6560
Remove the RunCommand resource previously deployed on the VM. If the script execution is still in progress, execution will be terminated.
6661

@@ -101,6 +96,101 @@ This command will retrieve current execution progress, including latest output,
10196
Get-AzVMRunCommand -ResourceGroupName "myRG" -VMName "myVM" -RunCommandName "RunCommandName" -Expand instanceView
10297
```
10398

99+
### Create or update Run Command on a VM using SourceScriptURI (storage blob SAS URL)
100+
Create or update Run Command on a Windows VM using a SAS URL of a storage blob that contains a PowerShell script. `SourceScriptUri` can be a storage blob’s full SAS URL or public URL.
101+
102+
> [!NOTE]
103+
> The SAS URL must provide read access to the blob. An expiration time of 24 hours is suggested for the SAS URL. SAS URLs can be generated on Azure portal using blob's options, or SAS token using `New-AzStorageBlobSASToken`. If generating SAS token using `New-AzStorageBlobSASToken`, your SAS URL = "base blob URL" + "?" + "SAS token from New-AzStorageBlobSASToken"
104+
105+
```azurepowershell-interactive
106+
Set-AzVMRunCommand -ResourceGroupName MyRG0 -VMName MyVMEE -RunCommandName MyRunCommand -Location EastUS2EUAP -SourceScriptUri <SourceScriptURI>
107+
```
108+
109+
### Get a Run Command Instance View for a VM after Creating or Updating Run Command
110+
111+
Get a Run Command for VM with Instance View. Instance View contains the execution state of Run Command (Succeeded, Failed, etc.), exit code, standard output and standard error generated by executing the script using Run Command. A non-zero ExitCode indicates an unsuccessful execution.
112+
113+
```azurepowershell-interactive
114+
$x = Get-AzVMRunCommand -ResourceGroupName MyRG -VMName MyVM -RunCommandName MyRunCommand -Expand InstanceView
115+
$x.InstanceView
116+
```
117+
118+
Expected output:
119+
```azurepowershell-interactive
120+
ExecutionState : Succeeded
121+
ExecutionMessage :
122+
ExitCode : 0
123+
Output :
124+
output : uid=0(root) gid=0(root) groups=0(root)
125+
HelloWorld
126+
127+
Error :
128+
StartTime : 10/27/2022 9:10:52 PM
129+
EndTime : 10/27/2022 9:10:55 PM
130+
Statuses :
131+
```
132+
`InstanceView.ExecutionState` -Status of user's Run Command script. Refer this state to know whether your script was successful or not.
133+
134+
`ProvisioningState` - Status of general extension provisioning end to end ( whether extension platform was able to trigger Run Command script or not).
135+
136+
### Create or update Run Command on a VM using SourceScript (script text)
137+
Create or update Run Command on a VM passing the script content directly to -SourceScript parameter. Use `;` to separate multiple commands.
138+
139+
```azurepowershell-interactive
140+
Set-AzVMRunCommand -ResourceGroupName MyRG0 -VMName MyVML -RunCommandName MyRunCommand2 -Location EastUS2EUAP -SourceScript "id; echo HelloWorld"
141+
```
142+
### Create or update Run Command on a VM using SourceCommandId
143+
Create or update Run Command on a VM using pre-existing `commandId`. Available commandIds can be retrieved using [Get-AzVMRunCommandDocument](/powershell/module/az.compute/get-azvmruncommanddocument).
144+
145+
```azurepowershell-interactive
146+
Set-AzVMRunCommand -ResourceGroupName MyRG0 -VMName MyVMEE -RunCommandName MyRunCommand -Location EastUS2EUAP -SourceCommandId ipconfig
147+
```
148+
149+
### Create or update Run Command on a VM using OutputBlobUri, ErrorBlobUri to stream standard output and standard error messages to output and error Append blobs
150+
151+
Create or update Run Command on a VM and stream standard output and standard error messages to output and error Append blobs.
152+
153+
```azurepowershell-interactive
154+
Set-AzVMRunCommand -ResourceGroupName MyRG0 -VMName MyVML -RunCommandName MyRunCommand3 -Location EastUS2EUAP EastUS2EUAP -SourceScriptUri <SourceScriptUri> -OutputBlobUri <OutputBlobUri> -ErrorBlobUri <errorbloburi>
155+
```
156+
157+
> [!NOTE]
158+
> Output and error blobs must be of type `AppendBlob` and their SAS URLs must provide read, append, create, write access to the blob. An expiration time of 24 hours is suggested for the SAS URL. If output or error blob does not exist, a blob of type AppendBlob will be created. SAS URLs can be generated on Azure portal using blob's options, or SAS token using New-AzStorageBlobSASToken. If generating SAS token using `New-AzStorageBlobSASToken`, SAS URL = base blob URL + "?" + SAS token from `New-AzStorageBlobSASToken`.
159+
160+
### Create or update Run Command on a VM, run the Run Command as a different user using RunAsUser and RunAsPassword parameters
161+
Create or update Run Command on a VM, run the Run Command as a different user using `RunAsUser` and `RunAsPassword` parameters. For RunAs to work properly, contact admin of VM and make sure user is added on the VM, user has access to resources accessed by the Run Command (Directories, Files, Network etc.), and in case of Windows VM, 'Secondary Logon' service is running on the VM.
162+
163+
```azurepowershell-interactive
164+
Set-AzVMRunCommand -ResourceGroupName MyRG0 -VMName MyVMEE -RunCommandName MyRunCommand -Location EastUS2EUAP EastUS2EUAP -SourceScriptUri <SourceScriptUri> -RunAsUser myusername -RunAsPassword mypassword
165+
```
166+
### Create or update Run Command on a Virtual Machine Scale Sets resource using SourceScriptUri (storage blob SAS URL).
167+
Create or update Run Command on a Virtual Machine Scale Sets resource using a SAS URL of a storage blob that contains a bash script.
168+
169+
```azurepowershell-interactive
170+
Set-AzVmssVMRunCommand -ResourceGroupName MyRG0 -VMScaleSetName MyVMSS -InstanceId 0 -RunCommandName MyRunCommand -Location EastUS2EUAP -SourceScriptUri <SourceScriptUri>
171+
```
172+
173+
> [!Note]
174+
> Note SAS URL must provide read access to the blob. An expiration time of 24 hours is suggested for SAS URL. SAS URLs can be generated on Azure portal using blob's options, or SAS token using New-AzStorageBlobSASToken. If generating SAS token using New-AzStorageBlobSASToken, SAS URL = base blob URL + "?" + SAS token from `New-AzStorageBlobSASToken`.
175+
176+
### Create or update Run Command on a VM instance using Parameter and ProtectedParameter parameters (Public and Protected Parameters to script)
177+
178+
```azurepowershell-interactive
179+
$PublicParametersArray = @([Microsoft.Azure.PowerShell.Cmdlets.Compute.Models.Api20210701.IRunCommandInputParameter]@{name='publicParam1';value='publicParam1value'},
180+
>> [Microsoft.Azure.PowerShell.Cmdlets.Compute.Models.Api20210701.IRunCommandInputParameter]@{name='publicParam2';value='publicParam2value'})
181+
182+
$ProtectedParametersArray = @([Microsoft.Azure.PowerShell.Cmdlets.Compute.Models.Api20210701.IRunCommandInputParameter]@{name='secret1';value='secret1value'},
183+
>> [Microsoft.Azure.PowerShell.Cmdlets.Compute.Models.Api20210701.IRunCommandInputParameter]@{name='secret2';value='secret2value'})
184+
185+
Set-AzVMRunCommand -ResourceGroupName MyRG0 -VMName MyVMEE -RunCommandName MyRunCommand -Location EastUS2EUAP -SourceScriptUri <SourceScriptUri> -Parameter $PublicParametersArray -ProtectedParameter $ProtectedParametersArray
186+
```
187+
Use `ProtectedParameter` to pass any sensitive inputs to script such as passwords, keys etc.
188+
189+
- Windows: Parameters and ProtectedParameters are passed to script as arguments are passed to script and run like this `myscript.ps1 -publicParam1 publicParam1value -publicParam2 publicParam2value -secret1 secret1value -secret2 secret2value`
190+
- Linux: Named Parameters and its values are set to environment config, which should be accessible within the `.sh` script. For Nameless arguments, pass an empty string to name input. Nameless arguments are passed to script and run like this - `myscript.sh publicParam1value publicParam2value secret1value secret2value`
191+
192+
193+
104194
### Delete RunCommand resource from the VM
105195
Remove the RunCommand resource previously deployed on the VM. If the script execution is still in progress, execution will be terminated.
106196

@@ -175,11 +265,10 @@ GET /subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers
175265
GET /subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Compute/virtualMachines/<vmName>/runcommands/<runCommandName>?$expand=instanceView&api-version=2019-12-01
176266
```
177267

178-
### Cancel a specific Run Command deployment
179-
180-
To cancel a running deployment, you can PUT or PATCH on the running instance of Run Command and specify a blank script in the request body. This will cancel the ongoing execution.
268+
### Delete a specific Run Command deployment
269+
181270

182-
You can also delete the instance of Run Command.
271+
Delete the instance of Run Command
183272

184273
```rest
185274
DELETE /subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Compute/virtualMachines/<vmName>/runcommands/<runCommandName>?api-version=2019-12-01

articles/virtual-machines/run-command-overview.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
title: Run scripts in a Windows or Linux VM in Azure with Run Command
33
description: This topic provides an overview of running scripts within an Azure virtual machine by using the Run Command feature
44
ms.service: virtual-machines
5-
author: cynthn
6-
ms.author: cynthn
7-
ms.date: 10/27/2021
5+
author: nikhilpatel909
6+
ms.author: erd
7+
ms.date: 11/03/2022
88
ms.topic: how-to
9-
ms.reviewer: jushiman
9+
ms.reviewer: erd
1010
ms.custom: devx-track-azurepowershell
1111

1212
---
@@ -19,9 +19,8 @@ Run Command uses the virtual machine (VM) agent to run scripts within an Azure W
1919
The original set of commands are action orientated. The updated set of commands, currently in Public Preview, are management orientated and enable you to run multiple scripts and has less restrictions. This article will explain the difference between the two sets of run commands and help you decide which set is the right one to use in your scenario.
2020

2121
> [!IMPORTANT]
22-
> **Managed Run Command** is currently in public preview.
23-
> This preview version is provided without a service-level agreement, and we don't recommend it for production workloads. Certain features might not be supported or might have constrained capabilities.
24-
> For more information, see [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
22+
> **Managed Run Command** is currently available in Azure CLI, PowerShell, and API at this time.
23+
2524

2625

2726
## When to use action or managed commands

0 commit comments

Comments
 (0)