Get resources in a managed resource group and resize VMs with PowerShell
This script retrieves resources from a managed resource group, and resizes the VMs in that resource group.
If you don't have an Azure subscription, create an Azure free account before you begin.
Sample script
# Get managed applications from known resource group
Get-AzManagedApplication -ResourceGroupName "DemoApp"
# Get ID of managed resource group
(Get-AzManagedApplication -ResourceGroupName "DemoApp").Properties.managedResourceGroupId
# Get virtual machines in the managed resource group
Get-AzResource -ResourceGroupName DemoApp6zkevchqk7sfq -ResourceType Microsoft.Compute/virtualMachines
# Get information about virtual machines in managed resource group
Get-AzVM -ResourceGroupName DemoApp6zkevchqk7sfq | ForEach{ $_.Name, $_.storageProfile.osDisk.osType, $_.hardwareProfile.vmSize }
## Resize virtual machines in managed resource group
$vm = Get-AzVM -ResourceGroupName DemoApp6zkevchqk7sfq -VMName demoVM
$vm.HardwareProfile.VmSize = "Standard_D2_v2"
Update-AzVM -VM $vm -ResourceGroupName DemoApp6zkevchqk7sfq
Script explanation
This script uses the following commands to deploy the managed application. Each command in the table links to command-specific documentation.
Command | Notes |
---|---|
Get-AzManagedApplication | List managed applications. Provide resource group name to focus the results. |
Get-AzResource | List resources. Provide a resource group and resource type to focus the result. |
Update-AzVM | Update a virtual machine's size. |
Next steps
- For an introduction to managed applications, see Azure Managed Application overview.
- For more information on PowerShell, see Azure PowerShell documentation.
Feedback
Submit and view feedback for