Categories
Computing

Spinning up a New VM via Azure PowerShell – Quick

 

A more in-depth version of this post can be found here.

This article assumes that you have the following:

  • An active Azure subscription.
  • An Azure PowerShell installation. (This differs from the normal PowerShell installation.)

Let’s get started. From the Azure Powershell command prompt, type:

Add-AzureAccount

Sign in to Azure.

To get your SubscriptionName, simply execute the cmdlet Get-AzureSubscription. Use the SubscriptionName in the command below.

Set-AzureSubscription -SubscriptionName "Free Trial" -CurrentStorageAccount "yourstorageaccount"

It’s important to note that the SubscriptionName is not the GUID you see when logging in.

Assuming you know the ImageName and the InstanceSize, your command will use New-AzureVMConfig to create the VM. (Note that this is in a ps1 file.) In this case, we’re also piping to Add-AzureProvisioningConfig, Set-AzureSubnet and New-AzureVM.

Screen Shot 2015-12-19 at 6.46.43 AM

Execute the contents simply by typing the filename. Since we’ve returned to the command prompt without issue, the VM is being created.

Screen Shot 2015-12-16 at 6.49.02 AM

We can see evidence of the machine being created at manage.windowsazure.com.

Screen Shot 2015-12-19 at 6.52.49 AM

Categories
Computing

Spinning Up a New VM via Azure Powershell

Screen Shot 2015-12-16 at 6.49.02 AMThis article assumes that you have two items:

  • An active Azure subscription.
  • An Azure Powershell installation.

Let’s get started. From the Azure Powershell command prompt, type:

Add-AzureAccount

Sign in to Azure with the appropriate credentials when prompted. After successfully signing in, you will see your subscription information.

Screen Shot 2015-12-11 at 12.28.11 PM

For the next command, Set-AzureSubscription, it’s recommended to specify the subscription being used. In my case, at this juncture, the command looks like the following:

Set-AzureSubscription -SubscriptionName "Free Trial" -CurrentStorageAccount "pwgazstore"

(pwgazstore is the Storage Account set up previously. Creating that is beyond the scope of this post.)

It’s important to note that the SubscriptionName is not the GUID you see when logging in. To get your SubscriptionName, simply execute the cmdlet Get-AzureSubscription.

Screen Shot 2015-12-11 at 12.38.03 PM

In order to find the name of the image you’d like to install, you can type the following.

Get-AzureVMImage | Select ImageName

As it turns out, even when piping with | more, it’s rather tedious to sift through the results. The list is quite long.

Luckily, it’s easy to create a function that acts like grep. To boot, you can simply type it at the command line and it’s yours!

function grep {
  $input | out-string -stream | select-string $args

}

See http://stackoverflow.com/questions/1485215/powershell-how-to-grep-command-output

Get-AzureVMImage | Select ImageName | grep AppX

The entire command then to spin up a VM looks like the following. This assumes your subnet is named “Subnet-1”. (Note in this case here, the ImageName is a custom image. Any image you can Get-AzureVMImage with should work.)

Screen Shot 2015-12-19 at 6.46.43 AM

This is a ps1 file that we can see when we ls. We can execute the contents simply by typing the filename. Since we’ve returned to the command prompt without issue, the VM is being created.

Screen Shot 2015-12-16 at 6.49.02 AM

We can see evidence of the machine being created at manage.windowsazure.com.

Screen Shot 2015-12-19 at 6.52.49 AM