Comments on: How to run scripts against multiple Azure VMs by using Run Command https://www.thomasmaurer.ch/2021/03/how-to-run-scripts-against-multiple-azure-vms-by-using-run-command/ Cloud and Datacenter Blog focusing on Microsoft Azure Wed, 22 Mar 2023 19:47:53 +0000 hourly 1 https://wordpress.org/?v=6.4.1 By: Jason https://www.thomasmaurer.ch/2021/03/how-to-run-scripts-against-multiple-azure-vms-by-using-run-command/#comment-891028 Wed, 22 Mar 2023 19:47:53 +0000 https://www.thomasmaurer.ch/?p=20854#comment-891028 Hey Thomas, thank for the excellent Video! hey can you help me solve this –

Invoke-AzAksRunCommand `
-ResourceGroupName $resourceGroup `
-Name gwae-util-01 `
-CommandID ‘RunPowerShellScript’ `
-ScriptPath ./testscript.ps1

—————————————————— Error Response
Invoke-AzAksRunCommand:
Line |
4 | -CommandID ‘RunPowerShellScript’ `
| ~~~~~~~~~~
| A parameter cannot be found that matches parameter name ‘CommandID’.

]]>
By: Mark https://www.thomasmaurer.ch/2021/03/how-to-run-scripts-against-multiple-azure-vms-by-using-run-command/#comment-884370 Wed, 19 Oct 2022 15:33:39 +0000 https://www.thomasmaurer.ch/?p=20854#comment-884370 How might you scope this to the subscription level. I’m struggling with doing so. I found one of the folks that commented but it seems like his script loops through each subscription and then through each resource and then the next subscription and so on….

Any help would be greatly appreciated.

]]>
By: David Ortiz https://www.thomasmaurer.ch/2021/03/how-to-run-scripts-against-multiple-azure-vms-by-using-run-command/#comment-880558 Tue, 26 Jul 2022 17:49:04 +0000 https://www.thomasmaurer.ch/?p=20854#comment-880558 In reply to Thomas Maurer.

Thank you that was the problem I was using powershell v5.
Thomas, if I wanted to use this script to copy a .exe from repository to the server, can it be done?

]]>
By: Thomas Maurer https://www.thomasmaurer.ch/2021/03/how-to-run-scripts-against-multiple-azure-vms-by-using-run-command/#comment-880337 Tue, 19 Jul 2022 08:46:01 +0000 https://www.thomasmaurer.ch/?p=20854#comment-880337 In reply to David Ortiz.

Hi Are you PowerShell version 7? https://www.thomasmaurer.ch/2019/07/how-to-install-and-update-powershell-7/

]]>
By: David Ortiz https://www.thomasmaurer.ch/2021/03/how-to-run-scripts-against-multiple-azure-vms-by-using-run-command/#comment-880308 Mon, 18 Jul 2022 23:48:39 +0000 https://www.thomasmaurer.ch/?p=20854#comment-880308 Hi,

I’m getting an error that says:

ForEach-Object : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:15
+ $myAzureVMs | ForEach-Object -Parallel {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : MetadataError: (:) [ForEach-Object], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.ForEachObjectCommand

]]>
By: Rakesh https://www.thomasmaurer.ch/2021/03/how-to-run-scripts-against-multiple-azure-vms-by-using-run-command/#comment-867003 Thu, 20 Jan 2022 02:26:03 +0000 https://www.thomasmaurer.ch/?p=20854#comment-867003 Hi Thomas,
How this can be achieved for Linux VM in azure.

]]>
By: Sam https://www.thomasmaurer.ch/2021/03/how-to-run-scripts-against-multiple-azure-vms-by-using-run-command/#comment-866536 Tue, 04 Jan 2022 07:17:59 +0000 https://www.thomasmaurer.ch/?p=20854#comment-866536 Hi Thomas,

I have multiple subscription and at one go I need to start it parallelly but it is not working for me. below is my code
$subs | ForEach-Object -parallel {
Select-AzSubscription -Subscription “$($_.name)” -ErrorAction Stop -ErrorVariable errorvar
$vmdetails+=Get-AzVM -Status | Where-Object {$_.StorageProfile.OsDisk.OsType -eq ‘Windows’ -and $_.PowerState -eq ‘VM running’}
$vmdetails
}
$vmdetails | ForEach-Object -Parallel {

$Extensions = Get-AzVMExtension -VMName $_.Name -ResourceGroupName $_.ResourceGroupName
if($Extensions.ProvisioningState -notcontains ‘Failed’)
{
$out2=Invoke-AzVMRunCommand -ResourceGroupName $_.ResourceGroupName -Name $_.Name -CommandId ‘RunPowerShellScript’ -ScriptPath .\RunScript.ps1
}
}
$ subs contains all my subscription details

If I remove parallel for subs then code works like a charm

]]>
By: Mariusz https://www.thomasmaurer.ch/2021/03/how-to-run-scripts-against-multiple-azure-vms-by-using-run-command/#comment-859561 Fri, 01 Oct 2021 11:47:03 +0000 https://www.thomasmaurer.ch/?p=20854#comment-859561 Hello
I got a case for run a PowerShell script to install some software on VM. I plan to use Runbook with managed identity. In that runbook I will gather all VMs from the RG, and than run the script which would be downloaded to the VM from Blob. All those actions needs to be done from runbook. I do not want to use Set-AzureVMCustomScriptExtension for that as it needs to be scheduled action per RG. Can I use Invoke-AzVMRunCommand with the localpath as a value for -script paramter ?

]]>
By: Matthew https://www.thomasmaurer.ch/2021/03/how-to-run-scripts-against-multiple-azure-vms-by-using-run-command/#comment-859267 Mon, 13 Sep 2021 12:43:58 +0000 https://www.thomasmaurer.ch/?p=20854#comment-859267 Hi Thomas,

For longer scripts that I want to run often, is it possible to add a custom default script to the eleven that Microsoft provides, or do I have to use ‘RunPowerShell Script’ every time and paste in my code?

Thanks

]]>
By: Fahim https://www.thomasmaurer.ch/2021/03/how-to-run-scripts-against-multiple-azure-vms-by-using-run-command/#comment-858759 Fri, 13 Aug 2021 09:42:44 +0000 https://www.thomasmaurer.ch/?p=20854#comment-858759 Hi Thomas,
How this can be achieved for Linux VM in azure.

]]>