Skip to content

fix issue found for Set-AzVmssVMRunCommand #19993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function Set-AzVMRunCommand_ScriptLocalPath {
if ($PSBoundParameters.ContainsKey("ScriptLocalPath"))
{
# Read Local File and add
$script = Get-Content -Path $ScriptLocalPath
$script = (Get-Content -Path $ScriptLocalPath) -join ";"
$PSBoundParameters.Add("SourceScript", $script)
# If necessary, remove the -ParameterA parameter from the dictionary of bound parameters
$null = $PSBoundParameters.Remove("ScriptLocalPath")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

function Set-AzVmssVMRunCommand_ScriptLocalPath {
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.Compute.Models.Api20210701.IVirtualMachineRunCommand])]
[CmdletBinding(DefaultParameterSetName='UpdateExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')]
[CmdletBinding(PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')]
param(
[Parameter(Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.Compute.Category('Path')]
Expand Down Expand Up @@ -186,12 +186,12 @@ function Set-AzVmssVMRunCommand_ScriptLocalPath {
if ($PSBoundParameters.ContainsKey("ScriptLocalPath"))
{
# Read Local File and add
$script = Get-Content -Path $ScriptLocalPath
$script = (Get-Content -Path $ScriptLocalPath) -join ";"
$PSBoundParameters.Add("SourceScript", $script)
# If necessary, remove the -ParameterA parameter from the dictionary of bound parameters
$null = $PSBoundParameters.Remove("ScriptLocalPath")
}
Az.Compute\Set-AzVMRunCommand @PSBoundParameters
Az.Compute\Set-AzVmssVMRunCommand @PSBoundParameters
}
}

2 changes: 1 addition & 1 deletion src/Compute/Compute.Autorest/docs/Az.Compute.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
Module Name: Az.Compute
Module Guid: 64d81db2-280c-4cff-a9f8-9e3ef386b229
Download Help Link: https://docs.microsoft.com/powershell/module/az.compute
Download Help Link: https://learn.microsoft.com/powershell/module/az.compute
Help Version: 1.0.0.0
Locale: en-US
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
external help file:
Module Name: Az.Compute
online version: https://docs.microsoft.com/powershell/module/az.compute/get-azgalleryapplication
online version: https://learn.microsoft.com/powershell/module/az.compute/get-azgalleryapplication
schema: 2.0.0
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
external help file:
Module Name: Az.Compute
online version: https://docs.microsoft.com/powershell/module/az.compute/get-azgalleryapplicationversion
online version: https://learn.microsoft.com/powershell/module/az.compute/get-azgalleryapplicationversion
schema: 2.0.0
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
external help file:
Module Name: Az.Compute
online version: https://docs.microsoft.com/powershell/module/az.compute/new-azgalleryapplication
online version: https://learn.microsoft.com/powershell/module/az.compute/new-azgalleryapplication
schema: 2.0.0
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
external help file:
Module Name: Az.Compute
online version: https://docs.microsoft.com/powershell/module/az.compute/new-azgalleryapplicationversion
online version: https://learn.microsoft.com/powershell/module/az.compute/new-azgalleryapplicationversion
schema: 2.0.0
---

Expand Down Expand Up @@ -34,7 +34,7 @@ $SASToken = New-AzStorageBlobSASToken -Context $ctx -Container $containerName -b
$storAcc = Get-AzStorageAccount -ResourceGroupName $rgName -Name $storAccName
$blob = Get-AzStorageBlob -Container $containerName -Blob $blobName -Context $storAcc.Context
$SASToken = New-AzStorageBlobSASToken -Container $containerName -Blob $blobName -Permission rwd -Context $storAcc.Context
$SASUri = $blob.ICloudBlob.Uri.AbsoluteUri + "?" +$SASToken
$SASUri = $blob.ICloudBlob.Uri.AbsoluteUri + $SASToken
New-AzGalleryApplicationVersion -ResourceGroupName $rgname -Location EastUS -GalleryName $galleryName -GalleryApplicationName $galleryApplicationName -name "0.1.0" -PackageFileLink $SASUri -Install "powershell -command 'Expand-Archive -Path package.zip -DestinationPath C:\\package\'" -Remove "del C:\\package"
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
external help file:
Module Name: Az.Compute
online version: https://docs.microsoft.com/powershell/module/az.compute/remove-azgalleryapplication
online version: https://learn.microsoft.com/powershell/module/az.compute/remove-azgalleryapplication
schema: 2.0.0
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
external help file:
Module Name: Az.Compute
online version: https://docs.microsoft.com/powershell/module/az.compute/remove-azgalleryapplicationversion
online version: https://learn.microsoft.com/powershell/module/az.compute/remove-azgalleryapplicationversion
schema: 2.0.0
---

Expand Down
2 changes: 1 addition & 1 deletion src/Compute/Compute.Autorest/docs/Remove-AzVMRunCommand.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
external help file:
Module Name: Az.Compute
online version: https://docs.microsoft.com/powershell/module/az.compute/remove-azvmruncommand
online version: https://learn.microsoft.com/powershell/module/az.compute/remove-azvmruncommand
schema: 2.0.0
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
external help file:
Module Name: Az.Compute
online version: https://docs.microsoft.com/powershell/module/az.compute/remove-azvmssvmruncommand
online version: https://learn.microsoft.com/powershell/module/az.compute/remove-azvmssvmruncommand
schema: 2.0.0
---

Expand Down
91 changes: 84 additions & 7 deletions src/Compute/Compute.Autorest/docs/Set-AzVMRunCommand.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
external help file:
Module Name: Az.Compute
online version: https://docs.microsoft.com/powershell/module/az.compute/set-azvmruncommand
online version: https://learn.microsoft.com/powershell/module/az.compute/set-azvmruncommand
schema: 2.0.0
---

Expand Down Expand Up @@ -37,18 +37,95 @@ The operation to create or update the run command.

## EXAMPLES

### Example 1: Simple Example
### Example 1: Create or update Run Command on a VM using a storage blob SAS URL
```powershell
Set-AzVMRunCommand -ResourceGroupName $rgname -VMName $vmname -RunCommandName 'firstruncommand'
Set-AzVMRunCommand -ResourceGroupName MyRG0 -VMName MyVMEE -RunCommandName MyRunCommand -Location EastUS2EUAP -SourceScriptUri "https://myst.blob.core.windows.net/mycontainer/myscript.ps1?sp=r&st=2022-10-27T21:02:35Z&se=2022-10-28T05:02:35Z&spr=https&sv=2021-06-08&sr=b&sig=0I%2FIiYayRwHasfasasfdasdfasdeTsQjLnpZjA%3D"
```

```output
Location Name Type
-------- ---- ----
eastus firstruncommand2 Microsoft.Compute/virtualMachines/runCommands
Location Name Type
-------- ---- ----
eastus2euap MyRunCommand Microsoft.Compute/virtualMachines/runCommands
```

The Set-AzVMRunCommand cmdlet updates properties for existing run command or adds a new run command to a virtual machine.
Create or update Run Command on a Windows VM using a SAS URL of a storage blob that contains .ps1 script.
Note SAS URL must provide read access to the blob.
An expiry 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, your SAS URL = base blob URL + "?" + SAS token from New-AzStorageBlobSASToken.

### Example 2: Create or update Run Command on a VM using a local script file.
```powershell
Set-AzVMRunCommand -ResourceGroupName MyRG0 -VMName MyVMEE -RunCommandName MyRunCommand -Location EastUS2EUAP -ScriptLocalPath "C:\MyScriptsDir\MyScript.ps1"
```

```output
Location Name Type
-------- ---- ----
eastus2euap MyRunCommand Microsoft.Compute/virtualMachines/runCommands
```

Create or update Run Command on a VM using a local script file that is on the client machine where cmdlet is executed.

### Example 3: Create or update Run Command on a VM using script text.
```powershell
Set-AzVMRunCommand -ResourceGroupName MyRG0 -VMName MyVML -RunCommandName MyRunCommand2 -Location EastUS2EUAP -SourceScript "id; echo HelloWorld"
```

```output
Location Name Type
-------- ---- ----
eastus2euap MyRunCommand2 Microsoft.Compute/virtualMachines/runCommands
```

Create or update Run Command on a VM passing the script content directly to -SourceScript parameter.
Use ';' to delimit multiple commands.

### Example 4: Create or update Run Command on a VM using commandId.
```powershell
Set-AzVMRunCommand -ResourceGroupName MyRG0 -VMName MyVMEE -RunCommandName MyRunCommand -Location EastUS2EUAP -SourceCommandId DisableWindowsUpdate
```

```output
Location Name Type
-------- ---- ----
eastus2euap MyRunCommand Microsoft.Compute/virtualMachines/runCommands
```

Create or update Run Command on a VM using pre-existing commandId.
Available commandIds can be retrieved using Get-AzVMRunCommandDocument.

### Example 5: Create or update Run Command on a VM and stream standard output and standard error messages to output and error Append blobs.
```powershell
Set-AzVMRunCommand -ResourceGroupName MyRG0 -VMName MyVML -RunCommandName MyRunCommand3 -Location EastUS2EUAP -ScriptLocalPath "C:\MyScriptsDir\MyScript.ps1" -OutputBlobUri "https://vivst.blob.core.windows.net/vivcontainer/output.txt?sp=racw&st=2022-10-27T22:18:36Z&se=2022-10-28T06:18:36Z&spr=https&sv=2021-06-08&sr=b&sig=HQAu3Bl%2BKMofYTjMo8o5hasfadsfasdF4jIkRJra4S5FlEo%3D" -ErrorBlobUri "https://vivst.blob.core.windows.net/vivcontainer/error.txt?sp=racw&st=2022-10-27T22:18:36Z&se=2022-10-28T06:18:36Z&spr=https&sv=2021-06-08&sr=b&sig=HQAu3Bl%2BKMofYTjMo8o5h%asfasdfgdT%2F4jasfasdf5FlEo%3D"
```

```output
Location Name Type
-------- ---- ----
eastus2euap MyRunCommand3 Microsoft.Compute/virtualMachines/runCommands
```

Create or update Run Command on a VM and stream standard output and standard error messages to output and error Append blobs.
Note output and error blobs must be of type AppendBlob and their SAS URLs must provide read, append, create, write access to the blob.
An expiry time of 24 hours is suggested for 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, your SAS URL = base blob URL + "?" + SAS token from New-AzStorageBlobSASToken.

### Example 6: Create or update Run Command on a VM, run the Run Command as a different user using RunAsUser and RunAsPassword parameters.
```powershell
Set-AzVMRunCommand -ResourceGroupName MyRG0 -VMName MyVMEE -RunCommandName MyRunCommand -Location EastUS2EUAP -ScriptLocalPath "C:\MyScriptsDir\MyScript.ps1" -RunAsUser myusername -RunAsPassword mypassword
```

```output
Location Name Type
-------- ---- ----
eastus2euap MyRunCommand Microsoft.Compute/virtualMachines/runCommands
```

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.

## PARAMETERS

Expand Down
91 changes: 84 additions & 7 deletions src/Compute/Compute.Autorest/docs/Set-AzVmssVMRunCommand.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
external help file:
Module Name: Az.Compute
online version: https://docs.microsoft.com/powershell/module/az.compute/set-azvmssvmruncommand
online version: https://learn.microsoft.com/powershell/module/az.compute/set-azvmssvmruncommand
schema: 2.0.0
---

Expand Down Expand Up @@ -38,18 +38,95 @@ The operation to create or update the VMSS VM run command.

## EXAMPLES

### Example 1: Set RunCommand by name
### Example 1: Create or update Run Command on a VMSS VM instance using a storage blob SAS URL
```powershell
Set-AzVmssVMRunCommand -InstanceId 3 -ResourceGroupName $rgname -RunCommandName "first" -VMScaleSetName $vmssname
Set-AzVmssVMRunCommand -ResourceGroupName MyRG0 -VMScaleSetName MyVMSS -InstanceId 0 -RunCommandName MyRunCommand -Location EastUS2EUAP -SourceScriptUri "https://myst.blob.core.windows.net/mycontainer/myscript.ps1?sp=r&st=2022-10-27T21:02:35Z&se=2022-10-28T05:02:35Z&spr=https&sv=2021-06-08&sr=b&sig=0I%2FIiYayRwHasfasasfdasdfasdeTsQjLnpZjA%3D"
```

```output
Location Name Type
-------- ---- ----
eastus first Microsoft.Compute/virtualMachineScaleSets/virtualMachines/runCommands
Location Name Type
-------- ---- ----
eastus2euap MyRunCommand Microsoft.Compute/virtualMachines/runCommands
```

Add RunCommand to an Instance of VMSS.
Create or update Run Command on a Windows VMSS VM instance using a SAS URL of a storage blob that contains .ps1 script.
Note SAS URL must provide read access to the blob.
An expiry 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, your SAS URL = base blob URL + "?" + SAS token from New-AzStorageBlobSASToken.

### Example 2: Create or update Run Command on a VMSS VM instance using a local script file.
```powershell
Set-AzVmssVMRunCommand -ResourceGroupName MyRG0 -VMScaleSetName MyVMSS -InstanceId 0 -RunCommandName MyRunCommand -Location EastUS2EUAP -ScriptLocalPath "C:\MyScriptsDir\MyScript.ps1"
```

```output
Location Name Type
-------- ---- ----
eastus2euap MyRunCommand Microsoft.Compute/virtualMachines/runCommands
```

Create or update Run Command on a VMSS VM instance using a local script file that is on the client machine where cmdlet is executed.

### Example 3: Create or update Run Command on a VMSS VM instance using script text.
```powershell
Set-AzVmssVMRunCommand -ResourceGroupName MyRG0 -VMScaleSetName MyVMSSL -InstanceId 1 -RunCommandName MyRunCommand2 -Location EastUS2EUAP -SourceScript "id; echo HelloWorld"
```

```output
Location Name Type
-------- ---- ----
eastus2euap MyRunCommand2 Microsoft.Compute/virtualMachines/runCommands
```

Create or update Run Command on a VMSS VM instance passing the script content directly to -SourceScript parameter.
Use ';' to delimit multiple commands.

### Example 4: Create or update Run Command on a VMSS VM instance using commandId.
```powershell
Set-AzVmssVMRunCommand -ResourceGroupName MyRG0 -VMScaleSetName MyVMSS -InstanceId 0 -RunCommandName MyRunCommand -Location EastUS2EUAP -SourceCommandId DisableWindowsUpdate
```

```output
Location Name Type
-------- ---- ----
eastus2euap MyRunCommand Microsoft.Compute/virtualMachines/runCommands
```

Create or update Run Command on a VMSS VM instance using pre-existing commandId.
Available commandIds can be retrieved using Get-AzVMRunCommandDocument.

### Example 5: Create or update Run Command on a VMSS VM instance and stream standard output and standard error messages to output and error Append blobs.
```powershell
Set-AzVmssVMRunCommand -ResourceGroupName MyRG0 -VMScaleSetName MyVMSS -InstanceId 1 -RunCommandName MyRunCommand3 -Location EastUS2EUAP -ScriptLocalPath "C:\MyScriptsDir\MyScript.ps1" -OutputBlobUri "https://vivst.blob.core.windows.net/vivcontainer/output.txt?sp=racw&st=2022-10-27T22:18:36Z&se=2022-10-28T06:18:36Z&spr=https&sv=2021-06-08&sr=b&sig=HQAu3Bl%2BKMofYTjMo8o5hasfadsfasdF4jIkRJra4S5FlEo%3D" -ErrorBlobUri "https://vivst.blob.core.windows.net/vivcontainer/error.txt?sp=racw&st=2022-10-27T22:18:36Z&se=2022-10-28T06:18:36Z&spr=https&sv=2021-06-08&sr=b&sig=HQAu3Bl%2BKMofYTjMo8o5h%asfasdfgdT%2F4jasfasdf5FlEo%3D"
```

```output
Location Name Type
-------- ---- ----
eastus2euap MyRunCommand3 Microsoft.Compute/virtualMachines/runCommands
```

Create or update Run Command on a VMSS VM instance and stream standard output and standard error messages to output and error Append blobs.
Note output and error blobs must be of type AppendBlob and their SAS URLs must provide read, append, create, write access to the blob.
An expiry time of 24 hours is suggested for 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, your SAS URL = base blob URL + "?" + SAS token from New-AzStorageBlobSASToken.

### Example 6: Create or update Run Command on a VMSS VM instance, run the Run Command as a different user using RunAsUser and RunAsPassword parameters.
```powershell
Set-AzVmssVMRunCommand -ResourceGroupName MyRG0 -VMScaleSetName MyVMSS -InstanceId 1 -RunCommandName MyRunCommand -Location EastUS2EUAP -ScriptLocalPath "C:\MyScriptsDir\MyScript.ps1" -RunAsUser myusername -RunAsPassword mypassword
```

```output
Location Name Type
-------- ---- ----
eastus2euap MyRunCommand Microsoft.Compute/virtualMachines/runCommands
```

Create or update Run Command on a VMSS VM instance, 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.

## PARAMETERS

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
external help file:
Module Name: Az.Compute
online version: https://docs.microsoft.com/powershell/module/az.compute/update-azgalleryapplication
online version: https://learn.microsoft.com/powershell/module/az.compute/update-azgalleryapplication
schema: 2.0.0
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
external help file:
Module Name: Az.Compute
online version: https://docs.microsoft.com/powershell/module/az.compute/update-azgalleryapplicationversion
online version: https://learn.microsoft.com/powershell/module/az.compute/update-azgalleryapplicationversion
schema: 2.0.0
---

Expand Down Expand Up @@ -356,7 +356,7 @@ COMPLEX PARAMETER PROPERTIES
To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables.


`INPUTOBJECT <IComputeIdentity>`: Identity Parameter
INPUTOBJECT <IComputeIdentity>: Identity Parameter
- `[CommandId <String>]`: The command id.
- `[GalleryApplicationName <String>]`: The name of the gallery Application Definition to be created or updated. The allowed characters are alphabets and numbers with dots, dashes, and periods allowed in the middle. The maximum length is 80 characters.
- `[GalleryApplicationVersionName <String>]`: The name of the gallery Application Version to be created. Needs to follow semantic version name pattern: The allowed characters are digit and period. Digits must be within the range of a 32-bit integer. Format: <MajorVersion>.<MinorVersion>.<Patch>
Expand All @@ -372,7 +372,7 @@ To create the parameters described below, construct a hash table containing the
- `[VMName <String>]`: The name of the virtual machine where the run command should be created or updated.
- `[VMScaleSetName <String>]`: The name of the VM scale set.

`TARGETREGION <ITargetRegion[]>`: The target regions where the Image Version is going to be replicated to. This property is updatable.
TARGETREGION <ITargetRegion[]>: The target regions where the Image Version is going to be replicated to. This property is updatable.
- `Name <String>`: The name of the region.
- `[EncryptionDataDiskImage <IDataDiskImageEncryption[]>]`: A list of encryption specifications for data disk images.
- `Lun <Int32>`: This property specifies the logical unit number of the data disk. This value is used to identify data disks within the Virtual Machine and therefore must be unique for each data disk attached to the Virtual Machine.
Expand Down
Loading