Skip to content
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

Documentation on Invoke-AzVmRunCommand unclear #15704

Closed
caroysMSFT opened this issue Aug 18, 2021 · 9 comments
Closed

Documentation on Invoke-AzVmRunCommand unclear #15704

caroysMSFT opened this issue Aug 18, 2021 · 9 comments
Assignees
Labels
Compute - VM Doc - Reference Service Attention This issue is responsible by Azure service team.

Comments

@caroysMSFT
Copy link

Description

src/Compute/Compute/help/Invoke-AzVMRunCommand.md

This video and examples show several details which are not mentioned in the documentation:

https://techcommunity.microsoft.com/t5/itops-talk-blog/how-to-run-scripts-in-your-azure-vm-by-using-run-command/ba-p/1362360

Cost

The things mentioned which are not clear in the documentation:

  1. That the script is expected to exist on the source machine (and it gets parsed in memory and sent to the VM)
  2. The existence of a --scripts parameter you can send a single command into (this may not be in the latest version)
  3. How exactly the hashtable works with regards to the input script. Is it passed as simple command line parameters to the resultant script, or does it do a replacement inside the script?

Some concrete examples would save a lot of customer confusion as well.

@caroysMSFT caroysMSFT added Engineering needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Aug 18, 2021
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Aug 18, 2021
@dingmeng-xue dingmeng-xue added Compute - VM Doc - Reference Service Attention This issue is responsible by Azure service team. labels Aug 19, 2021
@ghost
Copy link

ghost commented Aug 19, 2021

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Drewm3, @avirishuv.

Issue Details

Description

src/Compute/Compute/help/Invoke-AzVMRunCommand.md

This video and examples show several details which are not mentioned in the documentation:

https://techcommunity.microsoft.com/t5/itops-talk-blog/how-to-run-scripts-in-your-azure-vm-by-using-run-command/ba-p/1362360

Cost

The things mentioned which are not clear in the documentation:

  1. That the script is expected to exist on the source machine (and it gets parsed in memory and sent to the VM)
  2. The existence of a --scripts parameter you can send a single command into (this may not be in the latest version)
  3. How exactly the hashtable works with regards to the input script. Is it passed as simple command line parameters to the resultant script, or does it do a replacement inside the script?

Some concrete examples would save a lot of customer confusion as well.

Author: caroysMSFT
Assignees: -
Labels:

Engineering, Doc - Reference, Compute - VM, Service Attention

Milestone: -

@jaylabell
Copy link

@avirishuv can you take a look at this issue?

@jaylabell jaylabell assigned jaylabell and avirishuv and unassigned jaylabell Aug 19, 2021
@jaylabell
Copy link

@amjads1 can you take a look at this issue?

@jaylabell jaylabell assigned amjads1 and unassigned avirishuv Aug 19, 2021
@amjads1
Copy link

amjads1 commented Aug 24, 2021

Looking into the issue.

@amjads1
Copy link

amjads1 commented Sep 9, 2021

Working with @koralski to add additional clarity with examples in the existing documentation: https://github.com/Azure/azure-powershell/blob/main/src/Compute/Compute/help/Invoke-AzVMRunCommand.md

@koralski
Copy link

https://github.com/Azure/azure-powershell/blob/main/src/Compute/Compute/help/Invoke-AzVMRunCommand.md
Powershell doc needs to add:
-ScriptPath
Path of the script to be executed. When this value is given, the given script will override the default script of the command.
Path should point to a file from a local file system. The command will load it and send it for execution.

-Parameter
Specify parameters as key/value pairs to be passed at script execution.
Example (Windows VM):
Invoke-AzVMRunCommand -ResourceGroupName 'rgname' -Name 'vmname' -CommandId 'RunPowerShellScript' -ScriptPath 'sample.ps1' -Parameter @{"first" = "value1";"second" = "value2"}
Where arg1 and arg2 are defined as parameters in the sample.ps1:
param(
[string]$first,
[string]$second
)
Write-Host This is a sample script with parameters $first $second
Parameter value can be string type only and script is responsible for converting them to other types if needed.

For linux the parameters get converted to environment variables:
export first=value1 second=value2
set -- value1 value2 value3
These exports get added to the top of the bash script before execution.
Example (linux VM):
Invoke-AzVMRunCommand -ResourceGroupName 'rgname' -Name 'vmname' -CommandId 'RunShellScript' -ScriptPath 'sample.bash' -Parameter @{"first" = "value1";"second" = "value2"}
echo This is a sample bash script
echo Usage 1: Ordered parameters: $0 $1
echo Usage 2: Named exports: $first $second

Azure CLI:
--script
String should contain the script content to execute.
Example:
az vm run-command invoke -g myResourceGroup -n myVm --command-id RunShellScript --scripts "sudo apt-get update && sudo apt-get install -y nginx"

REST API
Reference to the spec to construct your URL and json body:
https://github.com/Azure/azure-rest-api-specs/blob/main/specification/compute/resource-manager/Microsoft.Compute/stable/2021-07-01/runCommands.json#L944

Example:
POST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/runCommand
{
"commandId": "RunPowerShellScript",
"script": [
"param(",
" [string]$first,",
" [string]$second",
")",
"Write-Host This is a sample script with parameters $first $second",
"Write-Host Done."
],
"parameters": [
{
"name": "first",
"value": "value1"
},
{
"name": "second",
"value": "value2"
}
]
}

@amjads1
Copy link

amjads1 commented Sep 30, 2021

Thanks @koralski for the updates!

mimckitt added a commit to mimckitt/azure-powershell that referenced this issue Oct 1, 2021
@mimckitt
Copy link
Contributor

mimckitt commented Oct 1, 2021

@amjads1 @koralski does the powershell update look correct?

https://github.com/Azure/azure-powershell/pull/16000/files

@mimckitt mimckitt self-assigned this Oct 1, 2021
@amjads1
Copy link

amjads1 commented Oct 7, 2021

@mimckitt Looks good to me. Thanks for the updates Micah!

@caroysMSFT I will go ahead and closed this issue now with the assumption that document will be updated in next week or so.

@amjads1 amjads1 closed this as completed Oct 7, 2021
BethanyZhou added a commit that referenced this issue Oct 28, 2021
* Update Invoke-AzVMRunCommand.md

#15704

* Update Invoke-AzVMRunCommand.md

* Update Invoke-AzVMRunCommand.md

* Update Invoke-AzVMRunCommand.md

* Update Invoke-AzVMRunCommand.md

* Update Invoke-AzVMRunCommand.md

* Update Invoke-AzVMRunCommand.md

* Update Invoke-AzVMRunCommand.md

* Update Invoke-AzVMRunCommand.md

Co-authored-by: Yunchi Wang <[email protected]>
Co-authored-by: Beisi Zhou <[email protected]>
BethanyZhou added a commit that referenced this issue Oct 29, 2021
* Update ci config to add tools/GeneratedModuleList.txt to skip list (#16216)

Co-authored-by: wyunchi-ms <[email protected]>

* Fix an issue in checking if we need to prompt survey. (#16232)

* Fix FirewallRuleName wildcard filtering in Get-AzSqlServerFirewallRule (#16237)

* Add Wildcard helper

* Fix wildcard filtering in Get-AzSqlServerFirewallRule

* Update src/Sql/Sql/ChangeLog.md

Co-authored-by: Beisi Zhou <[email protected]>

* [Storage] Add example for move datalakegen2 item with Sas (#16256)

* Update Invoke-AzVMRunCommand.md (#16000)

* Update Invoke-AzVMRunCommand.md

#15704

* Update Invoke-AzVMRunCommand.md

* Update Invoke-AzVMRunCommand.md

* Update Invoke-AzVMRunCommand.md

* Update Invoke-AzVMRunCommand.md

* Update Invoke-AzVMRunCommand.md

* Update Invoke-AzVMRunCommand.md

* Update Invoke-AzVMRunCommand.md

* Update Invoke-AzVMRunCommand.md

Co-authored-by: Yunchi Wang <[email protected]>
Co-authored-by: Beisi Zhou <[email protected]>

* Update notebook and spark job definition cmdlets to support folder path (#16269)

-update change log

-add example for specifying multi-level folder path

-update FolderName to FolderPath as PowerShell Team suggested

-update foldername description in help doc

-resolve some comments in code review

-update change log

-add new parameter foldername

Co-authored-by: Yunchi Wang <[email protected]>
Co-authored-by: wyunchi-ms <[email protected]>
Co-authored-by: kceiw <[email protected]>
Co-authored-by: Reggie Gibson <[email protected]>
Co-authored-by: Wei Wei <[email protected]>
Co-authored-by: Micah McKittrick <[email protected]>
Co-authored-by: YanjunGao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compute - VM Doc - Reference Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

7 participants