Switching Azure Mode

The Switch-AzureMode cmdlet switches between the Azure and Azure Resource Manager (AzureResourceManager) modules.

The new Azure Resource Manager module lets you manage your resources in an entirely new way.

Instead of creating individual resources and trying to use them together, begin by imagining the service you want to create, such as a web portal, a blog, a photo gallery, a commerce site, or a wiki.

Select a resource group template, including one of dozens in the Azure template gallery, or create your own. Each template provides a model of a complex service, complete with the resources that you need to support the service. Then use the template to create a resource group and its resources, and deploy and manage the related resources as a unit.

You can use Switch-AzureMode to switch between Azure modules as often as you like. To set an Azure module as the default for all sessions, use the Global parameter when switching between modes.

Bring your own VHD to Azure (uploading and Downloading VMs to Azure)

Want to move workloads into Azure?

Microsoft Azure has a few options, one of the easiest ways is with Microsoft Azure PowerShell.

$source = “D:\VirtualMachines\MyVm\**OS-DISK**.vhd”
$destination = “https://**mystoragepath**.blob.core.windows.net/vhd/**OS-DISK**.vhd”
Add-AzureVhd -LocalFilePath $source -Destination $destination -NumberOfUploaderThreads 5

Once the VHD file has been uploaded, it must be registered as either a OS disk or an additional disk. Use the “-OS” switch to specify whether it is a Linux or Windows OS.

Add-AzureDisk -DiskName ‘**OS-DISK**’ -MediaLocation $destination -Label ‘**OS-DISK**’ -OS Windows *** or Linux

Create a new Cloud/VM and attach the new **OS-DISK**
New-AzureVMConfig -DiskName ‘**OS-DISK**’ -Name ‘**OS-DISK**’ -InstanceSize **small** | Add-AzureDataDisk -Import -DiskName ‘**OS-DISK**’ -LUN 0 | New-AzureVM -ServiceName ‘*CLOUDNAME*’ -Location ‘**West US**’

To download the VHD from Azure the following can be used:

$source = “https://**mystoragepath**.blob.core.windows.net/vhd/**OS-DISK**.vhd”
$destination = “D:\VirtualMachines\MyVm\**OS-DISK**.vhd”

Save-AzureVhd -Source $source -LocalFilePath $destination -NumberOfThreads 5

For Physical or VMWare machines, the Microsoft Virtual Machine Converter 3.0 tool can be used.


Want to streamline the process ever more for Physical, Hyper-V or VMWare??? Take a look at Azure Site Recovery.




Get the latest Azure Windows Image

The following will get you the latest version of the image for the Windows 2012 R2 Server.

<–Start snippet–>

$imageFamily = “Windows Server 2012 R2 Datacenter”

$imagename = Get-AzureVMImage | where {$_.ImageFamily -eq $imageFamily } | sort PublishedDate -Descending | select -expandProperty ImageName -First 1

echo $imagename

<–End Snippet–>

NOTE: Use the $imagename value in your “New-AzureVM” Scripts.

How to create a PaaS website in Azure with PowerShell

Creating a new Website

To create a PaaS website in Azure the following command can be used.

<–Start Snippet –>

$websitelocation = “West US”

$websitename = “MyWebsite”

New-AzureWebsite -Location $websitelocation -Name $websitename

<–End Snippet –>


“test-azurename -Website $websitename”

This command could be run prior to ensure the name is not already in use.

Deployment Slots

To Create a “Deployment Slot” from an existing Website, or to create a new Deployment Slot the following can be used:

<–Start Snippet –>

$websiteslot = “UAT”

New-AzureWebsite -location $websitelocation -name $websitename -slot $websiteslot 

<–End Snippet –>

Swapping Deployment Slots

Switch your SIT – Systems Integration Testing slot with PROD – Production.

<–Start Snippet –>

$prodslot = “PROD”

$sitslot =”SIT”

Switch-AzureWebsiteSlot -Name $websitename -Name -Slot1 $sitslot -Slot2 $prodslot  

<–End Snippet –>


All websites are created in the “AzureWebsites.net” Domain. Each “Slot” are separate Azure sites and will be under the main website slot. As an example a site called SIT would be


Publishing an Azure Website

If you have a website deployment package you can publish it to azure using the following commands (note you can also publish using FTP,GIT, Visual Studio and other methods):

<–Start Snippet –>

$websitename = “MyWebsite”

$sitslot =”SIT”

$package = “C:\mywebfiles.zip”

Publish-AzureWebsiteProject -Name $websitename -Slot $sitslot  -Package $package

<–End Snippet –>



How to determine if an Azure web site, cloud, storageaccount or service bus name already exists.

The following can test whether a Microsoft Azure cloud service name, storage service name or service bus namespace name exists or not.

test-Azurename  -Service “CloudServiceName”

test-Azurename  -Storage “StorageAccountName”

test-Azurename  -ServiceBusNamespace “ServiceBusName”

test-Azurename  -Website “WebSiteName”

These parameters will return a “$true” value and can be used to determine how a script will handle a name already in use. This is useful for testing a name prior to creating a cloud service/website/storage account/ service bus automatically.


Installing the PowerShell Module for Azure

To install Azure PowerShell:

1.Install Microsoft Web Platform Installer. (Select “Free Download”) and run the application.

FROM -> http://www.microsoft.com/web/downloads/platform.aspx

2.Open Microsoft Web Platform Installer and search for Microsoft Azure PowerShell.

3.Click “Add” and select “Install”.

Install Azure PowerShell

4. Run “Microsoft Azure PowerShell”

Run PS

5. Run “Add-AzureAccount”

6. Logon to your Azure Account.

Use –> “Get-Command -Module Azure” <– for a list of Azure functions or “Show-Command” and search for name “Azure”.


**NOTE** These default values will be cached locally in the following file:

“%APPDATA%\Roaming\Windows Azure Powershell\AzureProfile.json”

The Following can provide additional functions to control the cached information.

Add-AzureAccount  –> Makes your Azure account and its subscriptions available in Windows PowerShell. It’s like logging into your Azure account in Windows PowerShell.

Get-AzureAccount –> Gets the Azure accounts that are available to Windows PowerShell.

Remove-AzureAccount –> Removes the account information from the configuration file

Get-AzureSubscription –-> Gets the subscriptions in your Azure account. You can use this cmdlet to get information about the subscription and to pipe the subscription to other cmdlets.Get-AzureSubscription requires access to your Azure accounts. Before you run Get-AzureSubscription, you must run the Add-AzureAccount cmdlet or the cmdlets that download and install a publish settings file (Get-AzurePublishSettingsFile,Import-AzurePublishSettingsFile.

Select-AzureSubscription –->  Sets and clears the current and default Azure subscriptions. The “current subscription” is the subscription that is used by default in the current Windows PowerShell session. The “default subscription” is used by default in all Windows PowerShell sessions. The “current subscription” label lets you specify a different subscription to be used by default for the current session without changing the “default subscription” for all other sessions.


The “default” subscription designation is saved in your subscription data file.

The session-specific “current” designation is not saved.

Set-AzureSubscription –->  The Set-AzureSubscription cmdlet establishes and changes the properties of an Azure subscription. You can use this cmdlet to create a new subscription or change the properties of an existing subscription.

Remove-AzureSubscription –-> Removes the subscription information from the configuration file

Switch-AzureMode –-> The Switch-AzureMode cmdlet switches between the Azure and Azure Resource Manager modules. These modules are not designed to be used in the same session.

To determine which module is in your current
session, use the Get-Module cmdlet.NOTE: The AzureResourceManager module is currently in preview and may not provide the same management capabilities as the Azure module.