Category Archives: Azure

What is Azure DNS? And how do I get started?

One of the new Azure services announced at Ignite was Azure DNS. A globally replicated and highly available DNS service leveraging Anycast for fast DNS responses from anywhere around the globe. Wow. Since it’s using well known management tools (Powershell) and integration interfaces (REST and C#) Azure DNS is really easy to build upon and maximize on the investment.

The only thing I’m missing (for obvious reasons) is the ability to register and manage domains at a registrar level. Hopefully a <insert domain registrar name here> Resource Provider is only a matter of time.

I’m very excited about this since I am wasting was wasting a boatload of money on two A0 VMs in an availability set hosting DNS. Since I had a small boat it only fit about $30/month.. 😉
With Azure DNS I’m only paying $0.25 per zone and $0.20 per 1 billion queries. So I basically cut my DNS cost by 99% and reduced my management cost by about the same amount.

Gettings started with Azure DNS

To sign up for Azure DNS, which is currently in preview, you’ll have to use Powershell. Be sure you have at least version 0.9.1 installed. Even tho DNS Cmdlets have been hiding since November 26th, 2014.
You easily can download and install the latest version with the help of this post.

Add-AzureAccount
Switch-AzureMode -Name AzureResourceManager
# Had to re-register the Microsoft.Network provider for the DNS feature to ever become Registered
Register-AzureProvider -ProviderNamespace Microsoft.Network
Register-AzureProviderFeature -ProviderNamespace Microsoft.Network -FeatureName azurednspreview

Wait until RegistrationState turns into Registered. It should happen almost instantly.

Get-AzureProviderFeature -ProviderNamespace Microsoft.Network -FeatureName azurednspreview | fl *

FeatureName : azurednspreview
ProviderName : Microsoft.Network
RegistrationState : Registered

Next we’ll create our first DNS Zone. All zones must be placed inside a Resource Group.

New-AzureResourceGroup -Name WE-DMZ-DNS -Location westeurope
New-AzureDnsZone -Name runbookautomation.se -ResourceGroupName WE-DMZ-DNS
# Get DNS zone name server
(Get-AzureDnsRecordSet -ZoneName runbookautomation.se -ResourceGroupName WE-DMZ-DNS -Name '@' -RecordType NS).Records

Next up is the slow and tricky part. The last row in the previous snippet expands the name servers of your newly created zone. These name servers need to be configured at your domain registrar.

This is how it looked like at my registrar:
binerodns

Once the DNS changes have replicated and Resolve-DnsName returns something like this you are good to go. The key property here is PrimaryServer.
resolvedns

Lastly we’ll create a CNAME record:

# Get the target Zone
$Zone = Get-AzureDnsZone -Name runbookautomation.se -ResourceGroupName WE-DMZ-DNS
# Create the DNS Record Set
$RecordSet = New-AzureDnsRecordSet -Name blog -RecordType CNAME -Ttl 3600 -Zone $Zone
# Add the CNAME value to the DNS Record Set
Add-AzureDnsRecordConfig -RecordSet $RecordSet -Cname blog-runbookautomation-se.azurewebsites.net
# Apply changes to Record Set in Azure
Set-AzureDnsRecordSet -RecordSet $RecordSet

Below is the complete code using variables for easier use.

Advertisements

Update Azure Powershell module with Powershell

A couple of months ago I shared a script that downloaded and installed the latest version of the Azure Powershell module. Since that time a lot of things have changed.

The module has moved from azure-sdk-tools to azure-powershell on GitHub!
The module has been updated from version 0.8.6 to version 0.9.1 with the help of over 3000 commits!
The module has gone from 434 cmdlets up to 761 cmdlets!

Below is a new snippet that leverages the GitHub API to download and install the latest Azure Powershell module:

Download and invoke the script to update. Or just run this one-liner:

Working with schedules in Azure Automation (and SMA)

The few of us that have started working with Azure Automation and/or SMA have probably noticed the lack of functionality that would equal a monitoring activity in Orchestrator.

I’ve seen some solutions which consist of a Runbook being set in an infinite loop with a sleep timer at the bottom.
In practice this method would replicated the desired functionality, that is, until the Runbook hits the maximum runtime value and kills the process. If you’re using Azure Automation this would also mean that you’ll be consuming Automation Minutes. 24/7.

What you’ll want to do with Azure Automation and SMA is to work with schedules to mimic a monitoring activity. And this can be a hassle to manage… Unless you’re using the right tools! 🙂
(Hint: Powershell.)

First we’ll want to create the required schedules. In 99% of the cases I work with hourly schedules at different minute intervals and I create them with the following script found at Technet Gallery.

If you use the “-Verbose” parameter you’ll get output on the schedule creation process.

And lastly we’ll want to assign Runbooks to the required schedules so the Runbook executes at the right time with the following script:

By piping to “Out-Gridview -Passthru” I can easily filter all the schedules and select the ones I want. Oh, and they script writes the intervals into the Description property of the schedules. This makes life a bit easier if you want the Runbook to execute, for example, every 5 minutes.

AaSchedules

The result would look something like this in the Azure Management Portal:

AaSetSchedules

I hope this helps you to manage your Automation Runbooks in a more efficient way and lower your Azure bill!

Again, the script can be found at: https://gallery.technet.microsoft.com/Generate-Azure-Automation-1dab9193

Install or update Microsoft Azure Powershell Module with Powershell

DEPRECATED POST – NEW AND UPDATED POST CAN BE FOUND HERE

After “manually” updating/installing my Azure Powershell Module from GitHub a couple of times to often, just in the last 4 months, I decided it’s time make a script for this! Or rather a function which I can reuse. 🙂

Install by simply executing:

Get-AzurePowershellModule -Install

You can also download the installer by omitting the -Install parameter. By omitting the -Install parameter the function will the path to the downloaded installer.
If you want more output you can use the parameter -ShowVersion to output the installed version (if any) and the latest version on GitHub.
You can also use -Verbose if you want even more output.

You’ll find the code below or can download directly from GetAzurePowershellModule.

function Get-AzurePowershellModule
{
    [cmdletbinding()]
    Param(
        [switch]$ShowVersion,
        [switch]$Install,
        [string]$Path=$null
    )
    BEGIN
    {
        If ($ShowVersion.IsPresent)
        {
            $Modules = Get-Module -ListAvailable
            $InstalledVersion = ($Modules | Where-Object {$_.Name -eq "Azure"}).Version.ToString()
            Write-Output "Installed: $InstalledVersion"
        }

    }
    PROCESS {
        Try
        {
            $WebSite = Invoke-WebRequest -Uri "https://github.com/Azure/azure-sdk-tools/releases/latest" -Method Get -TimeoutSec 30
        }
        Catch
        {
            Throw "Failed to get Web Content for Azure Powershell Module: $($_.Exception.Message)"
        }

        if ($ShowVersion.IsPresent)
        {
            $LatestVersion = ($WebSite.Links | Where-Object {$_.href -eq $WebSite.BaseResponse.ResponseUri.AbsolutePath}).innerText
            Write-Verbose "LatestVersion = $LatestVersion"
            Write-Output "Latest: $LatestVersion"
        }

        $DownloadURL = ($WebSite.Links | Where-Object {$_.InnerHTML -eq "Windows Standalone"}).href
        Write-Verbose "DownloadURL = $DownloadURL"

        If ($Path -ne $null)
        {
            if ((Test-Path $Path) -eq $false)
            {
                $OutFilePathRoot = (Get-Item $Path).Directory
            }
        }
        if ($OutFilePathRoot -eq $null)
        {
            $OutFilePathRoot = $env:TEMP
        }
        $OutFilePath = "$($OutFilePathRoot)\$($DownloadURL.Split("/")[-1])"
        Write-Verbose "OutFilePath = $($OutFilePath)"

        Invoke-WebRequest -Uri $DownloadURL -OutFile $OutFilePath -Method Get -TimeoutSec 60

        $LogPath = $OutFilePath.Split(".")
        $LogPath[-1] = "log"
        $LogPath = $LogPath -join "."
        Write-Verbose "LogPath = $($LogPath)"

        If ($Install.IsPresent)
        {
            Start-Process $OutFilePath -ArgumentList "/quiet /norestart /log $($LogPath)" -Wait -PassThru
        }
        else
        {
            Write-Output "Azure Powershell Module downloaded to: $($OutFilePath)"
        }
    }
    END
    {
        If ($Install.IsPresent)
        {
            Remove-Item -Path $OutFilePath -Force -Verbose
        }
    }
}

Microsoft Azure IaaS Cost Estimator Tool released!

Ever wondered what it would cost to run your datacenter on Azure? Good!

Are you running Virtual Machine Manger to manage your virtualization hosts? Even better! (But it doesn’t really matter)

Microsoft has released a cost estimator tool help you get a grasp of what your environment would cost to run on Azure!

Read more about the cost estimator tool at: Microsoft Azure IaaS Cost Estimator Tool