Skip navigation
Using PowerShell to Get Started in Microsoft Azure

Using PowerShell to Get Started in Microsoft Azure

Microsoft Azure provides a whole new way to manage your data. Rather than having to buy expensive hardware, configure the operating system, install and configure SQL Server, you can spin up a new Microsoft Azure virtual machine (VM) in a matter of minutes, and have a server ready to go.

Related: Does SQL Server Run Best on Microsoft Azure?

To get started, you need an Azure Subscription. I have an MSDN Subscription, which makes the process easy, and I get a monthly "allowance" for the charges for server and disk space usage. The service is part of the subscription and doesn't cost me more as long as I don't go over that limit. Set up an account (which doesn't cost anything), then go to the billing summary page and look up your Subscription ID, which is a GUID. Save that, as it'll be necessary in a bit.

The next thing you'll want to do is download the PowerShell Azure modules. You'll need to download and then run the install, and when you're done, you'll have the Azure PowerShell Console on your system. I chose not to use that, though. Once I completed the install I was able to open up the normal PowerShell ISE and use the Import-Module cmdlet.

Import-Module Azure

Now, the Azure cmdlets are available to me locally. The next thing you need to do is connect to your subscription. I used the Set-AzureSubscription cmdlet to do this, and this is where the Subscription ID GUID is necessary. My SubscriptionName is the same as the email address I used to set up my Azure account.

Set-AzureSubscription -SubscriptionName '[your subscription name]' -SubscriptionId '[your subscription id]'

Then, you can connect to your subscription (using the certificate method) by using the Get-AzurePublishSettingsFile cmdlet. This will open a web window and download the settings file to the directory of your choice. I downloaded it to my Downloads directory. The file will have an extension of .publishsettings and contains key information about your subscription. You can now use the Import-AzurePublishSettingsFile to set the Azure environment for your PowerShell session.

Import-AzurePublishSettingsFile -PublishSettingsFile 'C:\Users\[youruserid]\Downloads\[yoursettingsfilename].publishsettings'

I've already created a VM in Azure called AVMSQL01. I can now see that using the Get-AzureVM cmdlet.

Get-AzureVM cmdlet

To start up the VM, I use the Start-AzureVM cmdlet.

Start-AzureVM cmdlet

At this point, I want to start working in the VM, and to do that, I can use PowerShell remoting or Remote Desktop. To use Remote Desktop from within PowerShell, you can use the Get-AzureRemoteDesktopFile cmdlet and either save the .rdp file to a folder and double-click on that file, or you can launch RDP directly, like this.

Get-AzureRemoteDesktopFille cmdlet

Be sure to give yourself enough time for the server to start up and fully provision itself before launching RDP—but now you have a server available for testing. When you're done (assuming this is a test environment, like mine) make sure you stop the VM so you're not charged for time you're not actively using the VM.

Stop-AzureVM

In a future article, I'll discuss additional ways to configure your Azure VM via PowerShell.

Related: The Azure Experience

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish