public/Set-AzureVMSize.ps1
function Set-AzureVMSize { [cmdletbinding()] param ( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$VMName, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$NewVMSize, [Parameter(Mandatory=$true)] [string]$subscriptionName ) Process { # Get subscription name Try { Select-AzureRmSubscription -SubscriptionName $subscriptionName -ErrorAction Stop -Verbose | Out-Null } Catch { $error[0].Exception break } Try { # couldn't explicitly get the vm for whatever reaso by passing the rg and vm name's as string....so doing the below :( I <3 Microsoft. $vm = Get-AzureRmResource -ErrorAction Stop -Verbose | Where-Object {$_.name -like $VMName -and $_.resourcetype -eq 'Microsoft.Compute/virtualMachines'} $vm = $vm | Get-AzureRmVM if ($null -eq $VM) { Write-Warning "VM cannot be found, ensure you've referenced the correct subscription, or check your spelling and try again..." break } $vm.HardwareProfile.VmSize = $NewVMSize } Catch { $error[0].Exception break } Try { $results = $vm | Update-AzureRmVM -ErrorAction Stop -Verbose } Catch { $error[0].Exception break } return $results } #end process block } |