Skip to content

Instantly share code, notes, and snippets.

@msdotnetclr
Last active January 24, 2018 14:35
Show Gist options
  • Save msdotnetclr/7adfdba3000eb7269aed6633673252c0 to your computer and use it in GitHub Desktop.
Save msdotnetclr/7adfdba3000eb7269aed6633673252c0 to your computer and use it in GitHub Desktop.
Use PowerShell to start an Azure VM
# --- begin prerequisite ---
# interactive login to Azure Resource Manager with your Azure Account
Login-AzureRmAccount
# print the list of subscriptions you have access to
Get-AzureRmSubscription
# save your credential to a JSON file for auto-login later on
Save-AzureRmContext -Path "C:\private\azure-credential.json"
# --- end prerequisite ---
# --- begin script ---
Import-AzureRmContext -Path "C:\private\azure-credential.json"
Select-AzureRmSubscription -SubscriptionName "MySubscription"
$vm = Get-AzureRmVM -ResourceGroupName "MyResourceGroup" -Name "MyVM"
$vm | Start-AzureRmVM
# --- end script ---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment