Here is a quick script to create a new resource group, Storage account, storage account container and upload a VHD


Switch-AzureMode AzureResourceManager

$ResourceGroupNames = @('RG0','RG1')

foreach($ResourceGroupName in $ResourceGroupNames)
$location = 'North Central US'
$StorageAccountName = "sa01"
$StorageType = 'Standard_LRS'
$storageContainer = 'VHDImages'
$StorageAccountName = $StorageAccountName.ToLower()
$storageContainer = $storageContainer.tolower()
New-AzureResourceGroup -Name $ResourceGroupName -Location $location
New-AzureStorageAccount -ResourceGroupName $ResourceGroupName -AccountName $StorageAccountName -Type $StorageType -Location $location
$storageKey = Get-AzureStorageAccountKey -ResourceGroupName $ResourceGroupName -AccountName $StorageAccountName
$StorageContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $storageKey.Key1
New-AzureStorageContainer -Context $StorageContext -Name $storageContainer -Permission Off
Add-AzureVhd -LocalFilePath C:\Users\rplank\Downloads\rhel6-x64-template-azure.vhd -Destination "https://$" -ResourceGroupName $ResourceGroupName


Here is a quick script to use to upload Modules to Azure Automation.

Switch-AzureMode AzureResourceManager
$cred = Get-Credential 
Add-AzureAccount -Credential $cred

Select-AzureSubscription -SubscriptionId <SubscriptionID>
$ResourceGroup = Get-AzureResourceGroup -Name "IaaSAutomation"
$MyAutomationAccount = $ResourceGroup | Get-AzureAutomationAccount -Name "IaaSAutomation"
$MyAutomationAccount | New-AzureAutomationModule -name "xWebAdministration"  -ContentLink "" 
$MyAutomationAccount | New-AzureAutomationModule -name "xPhp"  -ContentLink "" 
$MyAutomationAccount | New-AzureAutomationModule -name "xWordPress"  -ContentLink "" 
$MyAutomationAccount | New-AzureAutomationModule -name "xMySQL"  -ContentLink ""


Today I am going to show you how to upload files to Azure Storage using the Azure Resource Manager PowerShell cmdlets. We are going to  upload all of our resources to the resource group and storage account that we created in this previous post. Once you have built your ARM template, VHD or DSC Configuration you can use the script below to upload the files to Azure storage. This scripts uploads files as a block blob type, you can read more about Azure Storage types here. I will cover this a bit more in a future blog post where I will show you how to upload a custom VHD to Azure, for now just note that you should not use the script below as is to upload a VHD.

If($cred -eq $null)
$cred = Get-Credential
$Account = Add-AzureAccount -Credential $Cred

Switch-AzureMode AzureResourceManager
$ResourceGroupName = 'Template'
$location = 'Central US'
$StorageAccountName = '<mystorageaccountname>'
$StorageType = 'Standard_LRS'
$storageContainer = '<Containername>'
$File = '<Enter the path here>'
$StorageAccountName = $StorageAccountName.ToLower()
$storageContainer = $storageContainer.ToLower()

$storageKey = Get-AzureStorageAccountKey -ResourceGroupName $ResourceGroupName -AccountName $StorageAccountName
$StorageContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $storageKey.Key1
Set-AzureStorageBlobContent -File $File -Context $StorageContext -Container $storageContainer -BlobType Block

Deploying Azure Resources with Azure Automation Blog Series




Today I am going to use the Azure PowerShell Module to create a new Azure Resource Manager storage account and 3 containers to store different resources that we will need throughout this blog series. The first container we are going to name vhdimages, we will store custom VHD images here, the second container is named armtemplates, we will store our json/Arm templates here and the last container is named configurations we will store a DSC configurations hear.  Optionally you could store everything in a single container but I have chosen to create separate containers for organizational purposes

If you have not used the Azure PowerShell Module yet you can download it here.  If you are reading this before October 2015 I recommend that you take a look at this Wiki article Deprecation of Switch Azure Mode in Azure PowerShell to understand some of the upcoming changes to the Azure PowerShell module. I plan to update all of these scripts to use the late September release of the module once it is release. Need to know how to connect to Azure with PowerShell check out this blog post.

There are a few rules to know while working with azure storage accounts, each storage account in azure must have a unique name, so it may take a few attempts to find a name that is not already in use by another azure user. Storage accounts and container also can only contain lowercase characters or number.

Switch-AzureMode AzureResourceManager

$ResourceGroupName = 'Templates'
$location = 'Central US'
$StorageAccountName = 'mystorageaccountname'
$StorageType = 'Standard_LRS'
$storageContainerVHD = 'VHDImages'
$storageContainerARM = 'Armtemplates'
$storageContainerDSC = 'Configurations'
$StorageAccountName = $StorageAccountName.ToLower()
$storageContainerVHD = $storageContainerVHD.tolower()
$storageContainerARM = $storageContainerARM.tolower()
$storageContainerDSC = $storageContainerDSC.tolower()
New-AzureResourceGroup -Name $ResourceGroupName -Location $location
New-AzureStorageAccount -ResourceGroupName $ResourceGroupName -AccountName $StorageAccountName -Type $StorageType -Location $location
$storageKey = Get-AzureStorageAccountKey -ResourceGroupName $ResourceGroupName -AccountName $StorageAccountName
$StorageContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $storageKey.Key1
New-AzureStorageContainer -Context $StorageContext -Name $storageContainerVHD -Permission Off
New-AzureStorageContainer -Context $StorageContext -Name $storageContainerARM -Permission Off
New-AzureStorageContainer -Context $StorageContext -Name $storageContainerDSC -Permission Off

Deploying Azure Resources with Azure Automation Blog Series

Today I am going to show you how to connect to Azure with the PowerShell Module. There are a few things that you should have in place before trying to connect. You will need to have an Azure Subscription and I recommend setting up Azure AD. I am not going to cover how to get Azure AD setup in this series, there are many blog post out there already on how to setup Azure AD Connect and ADFS.

What Credential should you use to connect to Azure, my recommendation is that you use an organization account that you have granted access to your Azure subscription. You have the option to use an Azure AD account also but if you have signed up to azure with a personal or gmail address you will not be able to authenticate to Azure with that account using the scripts below.  You will get this error

Add-AzureAccount : -Credential parameter can only be used with Organization ID


If you are running the Azure PowerShell module from your desktop you can use the following 3 lines to get connected to Azure.

$Cred = Get-Credential 
$Account = Add-AzureAccount -Credential $Cred
Select-AzureSubscription -SubscriptionId '<GUID>' 

If you are running the Azure PowerShell module from Azure Automation you can use this workflow as a template.

workflow ConnectToAzure
    #The name of the Automation Credential Asset this runbook will use to authenticate to Azure.
    $CredentialAssetName = 'DefaultAzureCredential'

    #Get the credential with the above name from the Automation Asset store
    $Cred = Get-AutomationPSCredential -Name $CredentialAssetName
    if(!$Cred) {
        Throw "Could not find an Automation Credential Asset named '${CredentialAssetName}'. Make sure you have created one in this Automation Account."

    #Connect to your Azure Account
    $Account = Add-AzureAccount -Credential $Cred
    if(!$Account) {
        Throw "Could not authenticate to Azure using the credential asset '${CredentialAssetName}'. Make sure the user name and password are correct."

    Select-AzureSubscription -SubscriptionID '<Guid>'

To use the above workflow you will need to create an credential asset in Azure Automation, I will cover this more in one of the Azure Automation blog post.

Deploying Azure Resources with Azure Automation Blog Series

I’ve decided to produce a single list of community based runbooks I have found useful. I will update this post as I find more.

Start Azure Automation Child Runbook

Send Email from Azure Automation from a Visual Studio Online Service Hook

New Service Request from Template


It has been awhile since I have blogged, and it is time to change that and share what I have been working on recently.

In this blog series I am going to walk you through how to deploy VMs in Azure using your own customized image using Azure Automation. To get started if you don’t already have an azure subscription you can sign up for one here.  We are going to cover a lot of different technologies/topics in this series so I plan to use this Intro blog post as an index for the series and a mast list of resources. As I find new resources for Azure I plan to update this post.

We will be using the Azure Resource Manager API in all of the blog post unless stated otherwise. (links to post will be updated as I post them)

  • Connecting to Azure with Azure PowerShell Module
  • ARM: Create Storage account with Azure PowerShell Module
  • ARM: Upload resources to Azure Storage
  • ARM: Create Azure Automation Account
  • ARM: IaaS Automation Setup Script
  • ARM: Uploading ARM PowerShell Module to Azure Automation
  • ARM: New-ARMDeployment Runbook
  • ARM: Json Templates
    • ARM Templates – Visual Studio overview
    • ARM Template – Standard Windows VM from Azure gallery
    • ARM Template – Domain Join
    • ARM Template – Custom image
    • ARM Template – Multiple VMs in Single deployment
  • ARM: Uploading ARM Templates to Azure Storage
  • ARM: Preparing VM Image to upload
    • ARM: Prepare RHEL Image for Azure
  • ARM: Upload VHD Images to Azure Storage
  • ARM: Deploy-VM Runbook
  • ARM: Invoke Runbook via Webhooks
  • ARM: Invoke Runbook from Service Manager
  • ARM: Link VM to Azure Automation DSC Configuration

Azure Resources

Azure Blogs

While you’re waiting for the next blog post check out my Azure DSC blogs

  1. Enable Azure Automation DSC Preview
  2. Register Servers to Azure Automation DSC
  3. Azure Automation DSC – Uploading Configurations
  4. Azure Automation DSC – Linking a Node to Node Configuration

In this post we are going to apply the DSC Configuration we uploaded in the last blog post to a Server Node.

Lets check the status of the compilation job


We can see that the status now says complete.

Check the status of the Node we want to apply the configuration too


you will notice that the NodeConfigurationName property is null, this means that there is not a configuration applied to the node.

Lets double check what Configurations we have loaded in Azure Automation DSC that we can apply to this node.


by running the cmdlet  $MyAutomationAccount | Get-AzureAutomationDscNodeConfiguration we see that we have two configurations, we are going to use the webserver.IIS and apply it to the DemoDSC Node by running:

$WebNode = $MyAutomationAccount | Set-AzureAutomationDscNode -NodeConfigurationName “webserver.IIS” -id “024b8929-f98b-11e4-80bb-000d3a9096e9”


the ID parameter on the Set-AzureAutomationDscNode command is the ID of the Node as you can see in the above image the demodsc node now has a configuration and the ID property matches the ID I entered in the cmdlet.

below you can see that initially we had the base 14 Windows Features installed, I forced the configuration to apply by running the Update-DSCConfiguration -wait -verbose cmdlet, if i would not have run this command the configuration would have applied the next time the DSC client checked in to Azure Automation DSC. After the DSC Configuration was applied 27 windows Features were installed.


In the past few blog post I have shown you how to get started with Azure Automation DSC, in the first blog post I coved how to Enable Azure Automation Preview and in the second how to Register Servers to Azure Automation DSC.  In this blog post I am going to go over how we can upload a DSC configuration to Azure Automation DSC.

First we will need a Configuration, there are a few public repositories the most popular two are on Github and  Powershellgallery. for my example we are going to use the configuration below.

Configuration WebServer
    node IIS
        WindowsFeature IIS
            Name = 'web-server'
            Ensure = 'Present'

save the above configuration as  webserver.ps1

Upload Configuration to Azure Automation DSC

$myConfig = $MyAutomationAccount | Import-AzureAutomationDscConfiguration -SourcePath 'C:\DSCConfigs\webserver.ps1' -Description "Test WebServer Config" -Published -force
$myConfig = Get-AzureAutomationDSCConfiguration -ResourceGroupName "mms-eus" -AutomationAccountName "MSDNAutomation"

Start Compilation Job

$myCompileJob = $myConfig | Start-AzureAutomationDscCompilationJob

Check Status of Compilation Job

$myCompileJob | Get-AzureAutomationDscCompilationJob


In the next blog post I will show you how to link the configuration to a Node.

This week at Microsoft Ignite the Azure Automation team provided a lot of guidance on what next version of Desired State Configuration will look like. They also announced that the Preview can be used now, you have to enable it via PowerShell. I would recommend watching the Heterogeneous Configuration Management Using Microsoft Azure Automation session for all the details straight from Microsoft.

Here are a few notable highlights:

· Currently management of Azure Automation DSC is 100% PowerShell based, within the next few months the UI should be added to your Azure portal.

· Pricing will be announced later this year.

· Don’t use this in production, it is a preview.

Now let’s get Azure Automation setup in your environment so you can start testing it.

You will need the Azure PowerShell Module version 0.9.1

Switch-AzureMode -Name AzureResourceManager
Register-AzureProvider -ProviderNamespace Microsoft.Automation
Register-AzureProviderFeature -FeatureName dsc -ProviderNamespace Microsoft.Automation

You can also download the script on TechNet Gallery