0 to Azure VM with PowerShell

I got a new laptop from MS, a thin and light model, great machine my thinking was can I function as a developer with all the additional requirements (SDKs, VM Test Environments etc..) that would entail.  For the most part everything was OK except I could not run many if any VMs on the Carbon without either running out of resources, mainly RAM.  So I turned to my new best friend Azure.  If anyone has an MSDN subscription it comes with Azure compute time, can’t speak to all SKUs, Ultimate comes with $150 credit each month. This blog post is my journey into Azure and automating the creation of test\dev environment, using Chocolatey.

This blog we will walk through the following:

  • Setting up machine to publish against Azure
  • Ensure Azure is Ready
    • Affinity Group
    • Storage Account
    • Associate Local Machine
    • Cloud Service
    • Network
  • Deploy VM
  • Configure and Install Components

Setting up machine to publish against Azure

Two prerequisite will be required:

Once the Azure PowerShell is installed we can get started.

      
On a computer running at least Windows 8 or Windows Server 2012, you can use the built-in Search. From the Start screen, begin typing power. This produces a scoped list of apps that includes Windows PowerShell and Azure PowerShell. Click either app to open the
console window. (To pin the app to the Start screen, right-click the icon.)

      
On a computer running a version earlier than Windows 8 or Windows Server 2012, you can use the Start menu. From the Start menu, click All Programs, click Azure, and then click Azure PowerShell.

Next up we’ll need your Azure publishing settings file.

This will open up the Azure portal you must sign into the account you wish to associate with this machine.

I use an internal employee Azure so I sign in through a federated page the public should see the regular Azure sig in either way you will see the following page and be prompted to download the subscription file.

Next import the subscription file:

With that you should be ready to publish your first VM to Azure.

Ensure Azure is Ready

Login to Azure and let’s make sure the infrastructure is in place. 

Affinity Group


 
Storage account


 
Associate local machine with azure
subscription

Cloud Service

Azure Service Name, this has to be unique within Azure and can be tested using the Test-AzureName command.

Network

Sample XML Import file

Once that is complete you should be ready for the deployment automation and build your very own Dev environment in Azure. 

Deploying the VM

There are generally two options either way we need an image we will apply to the VM, here I have chosen the most recent Server 2012 R2 image. 

Here we create an Azure VM with the New-AzureQuickVm

Or  creating a configuration then passing it along to New-Azure

I personally like option two because it gives you more control over what resources the VM will consume, network assignments etc…, however for the purposes of this blog just doing a quick VM.  I will attach scripts to do it both ways

In either case we need the following information:

  • ServiceName, this is the cloud service we created earlier, mine is marcusf-demotr. 
  • Name: this will be the name of the vm we are creating
  • ImageName: This is the Azure VM Image we are using to create the machine.  These are updated frequently and can be found by running Get-AzureVMImage this will be a big list so restrict down by running Get-AzureVMImage | Where ImageName –match
    server-2012-r2 | Select Name
  • Finally we need a user name and password I usually create credentials for this as follows

These credentials can be consumed as follows:

At this point you should have a fully functional VM in Azure, go ahead and log in and ensure you can reach the internet from this machine, this will be important later when we hit Chocolatey. 

NOTE: So if you are using your MSDN account there may be additional images that have Visual Studio preloaded along with the Azure SDK.  I am using a PFE account so Visual Studio is not included, this may be the same for your customers as well.  

Configuring the VM and Install the components

There is one major prerequisite here as Azure runs everything behind some type of SSL we have to install a Win RM certificate on our local machine here is a script that will do the trick.

Next up get the Uniform Resource Item

We are all set to start acting against our Azure VM remotely.

These may be some antiquated things and perhaps are not truly relevant but as a precaution on my dev environments I like to disable a few things, like User Access Control and Internet Explorer Enhanced Security Configuration.  These two seem to hinder my progress as I am dev and test on a machine. 

So the first configuration is to turn off UAC, the second is disabling IE enhanced security config and the final configuration is setting a DNS server.  What I have had happen in the past is I have a domain on IaaS and turned off the dns server lo and behold my newly created vm could no longer access the outside world, so chocolatey or anything dependent on the internet would fail. 

I start off by installing chocolatey, this is an open source project that allows Nuget type functionality for applications.  After chocolatey and as I have been known to do some web dev in the past I use Fiddler a lot and finally Visual Studio. 

You can find tons more packages at Choolatey.org. 

Enjoy, and don't hesitate to provide some feedback, there is always something to learn

Additional Resources

Chocolatey – https://chocolatey.org

Azure there is a 31 days of Azure series that will walk you through in greater detail Azure VMs among other things:  https://blogs.technet.com/b/chrisavis/archive/2013/01/25/the-31-days-of-servers-in-the-cloud-using-azure-iaas.aspx

More detail on Chocolatey and other goodness check out Matt Wrocks blog:  https://www.mattwrock.com/default.aspx

About Windows Azure Publish Settings File and how to create
your own Publish Settings File:  https://gauravmantri.com/2012/09/14/about-windows-azure-publish-settings-file-and-how-to-create-your-own-publish-settings-file/

What is a storage account? https://azure.microsoft.com/en-us/documentation/articles/storage-whatis-account/

What is a cloud service? https://azure.microsoft.com/en-us/documentation/articles/cloud-services-what-is/

Importance of Windows Azure Affinity Groups:   https://social.technet.microsoft.com/wiki/contents/articles/7916.importance-of-windows-azure-affinity-groups.aspx

Windows Azure and the Virtual
Networking – What it is: https://blogs.technet.com/b/bobh/archive/2013/01/09/windows-azure-and-virtual-networking-what-it-is-31-days-of-windows-servers-vms-in-the-cloud-part-9-of-31.aspx

Create a Windows Azure Network
using PowerShell: https://blogs.technet.com/b/kevinremde/archive/2013/01/19/create-a-windows-azure-network-using-powershell-31-days-of-servers-in-the-cloud-part-19-of-31.aspx

OneShot.ps1