Anton Maiorov
Anton Maiorov

Reputation: 183

Access Azure VM with PowerShell and MS Live credentials

I want to change the size an Azure VM with powershell. The reason is: I use machine for development. I need A2 size for 4 hours a day. The owner of the VM asked to switch the size of the machine to A0 when I do not develop. I have access to the Azure subscription with my MS Live account. Now I change the size manually through Azure Portal. I want to automate this task with PowerShell. The script should set the size to A2, wait for 4 hours and set it back to A0. I just want to doubleclick the script before starting my development and just forget about the question.

I have the following understanding of the general procedure:

  1. Run Import-AzurePublishSettings
  2. Run Select-AzureSubscription
  3. Get VM object with Get-AzureVM
  4. Run Set-AzureVMSize
  5. Update-AzureVM

I can not get publish profile, because I do not own the machine. Is there a way to authenticate with MS Live account?

Upvotes: 0

Views: 86

Answers (1)

larsro
larsro

Reputation: 76

Skip the Import-Azurepublish and do a Add-AzureAccount instead. That will popup UI for authenticating with your MS Live account.

Once that is done you can use Select-AzureSubscription

For Classic Deployment you need this:

# authenticate if no account is already added to the powershell session
if (!(Get-AzureAccount)){ Add-AzureAccount }

# Get the vm object out of azure
$vm = get-azurevm | where name -eq "name of the vm"

# Now all you need is to is update the VM with its new size:

$vm | Set-AzureVMSize -InstanceSize Medium | Update-AzureVM

If the VM is deployed via the Resource Manager (RM Model)

if (!(Get-AzureRMContext)){ Add-AzureRmAccount } 
Select-AzureRmSubscription -SubscriptionId "{subscriptionId}" 

$vm = Get-AzureRmVm | where name -eq "{vmName}" 
$vm.HardwareProfile.vmSize = "Medium" 
Update-AzureRmVM -VM $vm 

btw. Medium is what A2 is called in the API.

Upvotes: 1

Related Questions