Stop Multiple VMs in Multiple Resource Groups

List All VMs

Get-AzVM -ResourceGroupName 'az104-06*' -Status
ResourceGroupName         Name      Location       VmSize  OsType           NIC Provisioning Zone PowerState MaintenanceAllowed
-----------------         ----      --------       ------  ------           --- ------------ ---- ---------- ------------------
AZ104-06-RG1      az104-06-vm0 southeastasia Standard_B1s Windows az104-06-nic0    Succeeded      VM running
AZ104-06-RG1      az104-06-vm1 southeastasia Standard_B1s Windows az104-06-nic1    Succeeded      VM running
AZ104-06-RG2      az104-06-vm2 southeastasia Standard_B1s Windows az104-06-nic2    Succeeded      VM running
AZ104-06-RG3      az104-06-vm3 southeastasia Standard_B1s Windows az104-06-nic3    Succeeded      VM running

Stop All VMs

Get-AzVM -ResourceGroupName 'az104-06*' | Stop-AzVM -Force -AsJob

Get job statuses

Get-Job
Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
1      PowerShell.OnI…                 Stopped       False                                …
2      Long Running O… AzureLongRunni… Running       True            localhost            Stop-AzVM
3      Long Running O… AzureLongRunni… Running       True            localhost            Stop-AzVM
4      Long Running O… AzureLongRunni… Running       True            localhost            Stop-AzVM
5      Long Running O… AzureLongRunni… Running       True            localhost            Stop-AzVM

Wait until all jobs complete.

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
1      PowerShell.OnI…                 Stopped       False                                …
2      Long Running O… AzureLongRunni… Completed     True            localhost            Stop-AzVM
3      Long Running O… AzureLongRunni… Completed     True            localhost            Stop-AzVM
4      Long Running O… AzureLongRunni… Completed     True            localhost            Stop-AzVM
5      Long Running O… AzureLongRunni… Completed     True            localhost            Stop-AzVM

Check status again

ResourceGroupName         Name      Location       VmSize  OsType           NIC Provisioning Zone     PowerState MaintenanceAllowed
-----------------         ----      --------       ------  ------           --- ------------ ----     ---------- ------------------
AZ104-06-RG1      az104-06-vm0 southeastasia Standard_B1s Windows az104-06-nic0    Succeeded      VM deallocated
AZ104-06-RG1      az104-06-vm1 southeastasia Standard_B1s Windows az104-06-nic1    Succeeded      VM deallocated
AZ104-06-RG2      az104-06-vm2 southeastasia Standard_B1s Windows az104-06-nic2    Succeeded      VM deallocated
AZ104-06-RG3      az104-06-vm3 southeastasia Standard_B1s Windows az104-06-nic3    Succeeded      VM deallocated

References