Shutting down Azure VMs based on Resource Group tags

Shutting down your non-production VM’s when you’re not using them in a great way to save money. There’s a couple of good Powershell scripts that make this easy to do by Resource Group – but when you want to be a little more granular, and actually automate across resource groups you need a smarter script – this is where Resource tagging comes in.

This script in basically my v1, simple powershell script designed to be run on demand manually. I’ll be publishing the more fully featured version in the Azure Automation Runbook Gallery shortly. That script has had to have a few workarounds put in to deal with issues arising from being a Powershell Workflow and running in Parallel, so I thought it worthwhile to share the simpler version here.

Cloud Solution Architect at Microsoft in the UK.

Azure AD B2C – Using the graph API

There’s a really good guide for getting started with CRUD operations in a AAD B2C tenant on the Azure documentation site;
https://azure.microsoft.com/en-gb/documentation/articles/active-directory-b2c-devquickstarts-graph-dotnet/

As per usual, I’ve ended up putting some powershell together to make it a bit more repeatable when I have to do this for multiple AAD tenants.

This particular script creates the application in the AAD tenant. I’ll be posting further scripts that show off doing some clever stuff when I’ve finished testing and polishing them.

Cloud Solution Architect at Microsoft in the UK.

Azure B2C Unified sign up with Page UI customization

When crafting a new Unified sign-up or sign-in page policy in the Azure Portal I managed to get this error

#error=server_error&error_description=AADB2C90001: The server hosting resource 'https://meetr.azurewebsites.net/account/signinorsignup' is not enabled for CORS requests. Ensure that the 'Access-Control-Allow-Origin' header has been configured.
Correlation ID: 613d1479-d146-4b89-abb8-3264730f5991
Timestamp: 2016-04-13 18:33:30Z

Of course, i’d been a bit quick off the mark and not yet changed my Asp.net website to accept Cross Origin Requests.

Here’s what you’ll need to add to your unified Sign In page to fix the error

Response.AppendHeader("Access-Control-Allow-Origin", "https://login.microsoftonline.com");

Code wise, here’s how the Controller Action and View look;

Cloud Solution Architect at Microsoft in the UK.

Azure ARM Reserved Public Ip Addresses via Powershell

I’ve had the situation where the full allocation of IP addresses are needed up front for firewall configuration. This isn’t so bad when you only need a few, but if you’re going for your full allocation of 20 (or more if you’ve spoken to Microsoft Support) then it can get a little tedious using the Azure Portal UI.

The typical output from this should be something like;

My_IPBag_1 13.79.152.42 Succeeded
My_IPBag_2 13.79.159.10 Succeeded
My_IPBag_3 52.169.176.221 Succeeded
My_IPBag_4 13.79.156.94 Succeeded
My_IPBag_5 13.79.157.129 Succeeded
My_IPBag_6 13.79.153.147 Succeeded
My_IPBag_7 13.79.157.117 Succeeded
My_IPBag_8 13.79.153.183 Succeeded
My_IPBag_9 13.79.154.248 Succeeded
My_IPBag_10 13.79.157.10 Succeeded
My_IPBag_11 13.79.155.174 Succeeded

Note that the assigned IP addresses are not in a continuous range 🙂

If you do try to obtain more than 20 Public IP Addresses in your subscription then you’ll get this friendly error message.

New-AzureRmPublicIpAddress : Cannot create more than 20 public IP addresses with static allocation method for this subscription in this region.

Cloud Solution Architect at Microsoft in the UK.

Azure AD b2c error – could not load file or assembly ‘microsoft.identitymodel.protocol.extensions’

Following the Azure B2C Dev Quickstarts resulted in a build failure…

Could not load file or assembly ‘Microsoft.IdentityModel.Protocol.Extensions’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

The quick fix is to update the Nuget package reference for the Protocol Extensions from version 1.0.0.0 to 1.0.2.33 using the Visual Studio Nuget package manager.

Subsequently the build then fails with this error;

The following errors occurred while attempting to load the app.
– No assembly found containing an OwinStartupAttribute.
– No assembly found containing a Startup or [AssemblyName].Startup class.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of “false” in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.

The fix for this one is to check your Startup.cs file for the OWIN assembly declaration.

These few changes should then result in a successful build.

Cloud Solution Architect at Microsoft in the UK.