Skip to content

Instantly share code, notes, and snippets.

@glombard
Last active December 28, 2015 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glombard/7452810 to your computer and use it in GitHub Desktop.
Save glombard/7452810 to your computer and use it in GitHub Desktop.
Starting an Azure Virtual Machine from the command-line with PowerShell
# Get WebPICmd from: http://go.microsoft.com/fwlink/?LinkId=255386
# Direct download link:
# x64: http://download.microsoft.com/download/7/0/4/704CEB4C-9F42-4962-A2B0-5C84B0682C7A/WebPlatformInstaller_amd64_en-US.msi
# x86: http://download.microsoft.com/download/7/0/4/704CEB4C-9F42-4962-A2B0-5C84B0682C7A/WebPlatformInstaller_x86_en-US.msi
webpicmd /Install /Products:WindowsAzurePowershell /AcceptEula
webpicmd /List /ListOption:Installed | findstr "PowerShell"
# Import-Module "${env:ProgramFiles(x86)}\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"
For a list of all Azure cmdlets type 'help azure'.
For a list of Windows Azure Pack cmdlets type 'Get-Command *wapack*'.
For Node.js cmdlets type 'help node-dev'.
For PHP cmdlets type 'help php-dev'.
For Python cmdlets type 'help python-dev'.
C:\> Add-AzureAccount
VERBOSE: Account "xxxxx@msn.com" has been added.
VERBOSE: Subscription "Visual Studio Ultimate with MSDN" is selected as the default subscription.
VERBOSE: To view all the subscriptions, please use Get-AzureSubscription.
VERBOSE: To switch to a different subscription, please use Select-AzureSubscription.
Get-AzureAccount
Get-AzurePublishSettingsFile
$file = dir ~\Downloads\*credentials.publishsettings | sort LastWriteTime -Descending | select -expand FullName
Import-AzurePublishSettingsFile -PublishSettingsFile $file
del $file
Get-AzureSubscription
# Start the Azure Virtual Machine first:
$name = 'MyVM'
Start-AzureVM -Name $name -ServiceName $name
Get-AzureVM
# Start Remote Desktop session:
$port = get-AzureVM -ServiceName $name | Get-AzureEndpoint -Name 'Remote Desktop' | select -ExpandProperty Port
$server = "${name}.cloudapp.net:$port"
Invoke-Expression "mstsc.exe /v:$server /f"
# Stop-AzureVM -ServiceName $name -Name $name -StayProvisioned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment