Author Archives: devkeydet

About devkeydet

Global Sales Director - PowerApps & Flow

Contributing to Azure Quickstart Templates for Azure Government

The Azure Quickstart Templates are community contributed ARM templates to help people get started with and accelerate the deployment of common scenarios in Azure.  Unfortunately, many of the templates don’t work in Azure Government.  Since these templates are contributed by the community, the original contributors may not even know that they need to update their templates.  The good news is that ensuring new templates work in multiple Azure environments is part of the current guidance.  However, for existing templates, it’s going to take members of the community, like you and me, to ensure that these templates get updated.  I’ve updated a few of them already. 

Based on feedback from others who I’ve been helping contribute, I’ve recorded some “how to” videos that focus on the Azure Government specific nuances.  I’d like to encourage you to consider contributing.

I’ve organized this into two parts.  The first part really just focuses on the GitHub part of contributing.  In fact, the template in the first video already works with Azure Government.  I really just walk you through how to update the README.md file and metadata.json file, then submit the pull request.

In the second video, I make a number of common changes necessary in order to get a template deployable to Azure Government.

While this walkthrough focuses on Azure Government, these are the same kinds of changes necessary to make templates deployable to other environments like AzureChina, Azure Stack, and others.

HTH

@devkeydet

Custom Autoscale for ARM Virtual Machines in Azure Government

Scenario:

“I want to automatically scale Azure Resource Manager (ARM) Virtual Machines in Azure Government.  I do not want to use Virtual Machine Scale Sets (VMSS).”

The video below walks through the following code sample, which addresses the scenario above:

https://github.com/devkeydet/AzureAutomationAutoScaleVirtualMachines

My sample is an adaptation of the Custom Auto Scaling for Azure ARM Virtual Machines sample.  The video explains the differences, how the code works and how to get it deployed and running.

As I point out at the end of the video, this general approach could also be adapted to implement custom autoscale for other services in Azure Government such as App Service, VMSS, and SQL Database.

@devkeydet

Install Windows Updates on an Azure VM using Azure Automation

Scenario:

“I want to use Azure Automation to install Windows Updates on my Azure VM.  All the examples I have come across were written with Azure Service Management (ASM) based PowerShell scripts.  Are there any examples of doing this with Azure Resource Manager (ARM) VMs?”

I looked around at other examples of how to do this, including this one:

https://gallery.technet.microsoft.com/scriptcenter/Manage-Windows-Updates-on-160f40bc

I too only found ASM examples.  The video below is a walkthrough of using the sample scripts from my GitHub repository:

https://github.com/devkeydet/AutomationInvokeWindowsUpdateAzureRmVM

Some notes about my scripts which make them different from most of the ASM examples I reviewed.  The runbook script uses PowerShell Remoting to invoke commands on the VM.  WinRM is required for PowerShell Remoting.  ARM VMs don’t have WinRM enabled by default.  My video doesn’t cover configuring WinRM.  I’d recommend enabling WinRM through ARM templates as described here:

https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-winrm/

If you have existing ARM VMs that need to have WinRM enabled, see:

http://www.techdiction.com/2016/02/12/create-a-custom-script-extension-for-an-azure-resource-manager-vm-using-powershell/ 

I use Azure Automation DSC to ensure that the VMs have the prerequisite PSWindowsUpdate and TaskRunner modules installed locally.  For simplicity, the runbook script accesses the VM using PowerShell Remoting over ssl via public IP/DNS label.  If you prefer to not expose VMs over the public internet you could consider using Azure Automation Hybrid Runbook Workers:

https://azure.microsoft.com/en-us/documentation/articles/automation-hybrid-runbook-worker/#starting-runbooks-on-hybrid-runbook-worker

@devkeydet

Manual failover of Azure File storage

UPDATE (10/13/2016): Added video

Customer scenario:

“I have a deployment architecture in Azure which requires web servers (but can be anything) communicate with a remote file share.  I want to use Azure File storage.  I also need to maintain a geographically redundant environment in another Azure region.  I am required to demonstrate end to end execution of my disaster recovery plan.  The end result must show all pieces of my deployment architecture running in the other region. “

The first question to this scenario might be: “What about Geo-redundant storage (GRS)?”  The answer to that question is that since, at the time of this post, GRS doesn’t give you fine grained control to force Azure Storage to switch to using the replica in the other region, it won’t meet the customer scenario of being able to prove storage has failed over.  Note that if you are ok with trusting that GRS will failover in the event of a disaster (as documented) and aren’t *required* to prove it, then you can stop reading this post.  Just use GRS.  “What about Read-access geo-redundant storage (RA-GRS)?  Can’t I rely on RA-GRS to perform the replication for me and just use something like AzCopy to copy the read-only replica into a new storage account? The end result being a fully functioning share based on the replica?” You could if Azure File storage supported RA-GRS.  It doesn’t at the time of this post.

I put together a little code sample to demonstrate one approach to address the scenario above:

https://github.com/devkeydet/AzureFileShareOnewaySync

Here is a video walkthrough of the sample:

@devkeydet

Using postman with Azure AD

UPDATE (27JUN2017): I’ve been ping’d a few times about updating this post since it uses the old portal UI.  It seems many people land here through their favorite search engine.  John Gallant has an updated post here that should server the same purpose: http://blog.jongallant.com/2017/03/azure-active-directory-access-tokens-postman/

Postman (https://www.getpostman.com/) is a popular tool for testing out a web api.  Figuring out how to use it with a resource protected by Azure AD is a bit daunting for many.  I created this walkthrough video to help you understand how to use the postman oauth 2 authorization helper with AAD.

Here are the values I use in the video so you can copy/paste them:

Auth URL: https://login.windows.net/common/oauth2/authorize?resource=https%3A%2F%2Fb2byour.resource.domain%2F

Access Token URL: https://login.microsoftonline.com/common/oauth2/token

@devkeydet

 

Using an ERD tool to create CRM entities

I get asked this now and then:

“I want to use Erwin [or Visio or Visual Studio or…] to graphically design the CRM entity model, then have the actual CRM entities generated off of the tool I used to design the entities.”

While I am not aware of a direct way to do this with any ERD tools, there is a multi-step process you can use as long as your ERD designer can generate a SQL or Access database:

  • Use your ERD designer to model your entities, fields and relationships
  • Generate a SQL or Access database from the designer
  • Use https://xrmspeedy.codeplex.com/ to generate the CRM entities from the database

Of course, you’ll need to make sure you don’t pick data types in your diagram that the xrmspeedy tool can’t translate to CRM types, but this approach can be used as a productivity enhancement to those who prefer to diagram out their entities and generated them.  Since this is an open source tool, you might consider contributing feedback if you have ideas for improvement.  After a little trial and error, I’ve found I get value out of using Visual Studio’s Entity Framework Designer plus this tool when brainstorming data models and building POCs.  Your Mileage May Vary (YMMV).

@devkeydet

Batch updating fields with crmsvcutil generated code

Scenario:

“I love early bound code because of compile time checking, LINQ query enablement, etc.  I want to batch update a bunch of records, but OrganizationServiceContext.SaveChanges() executes under the hood as one web service call per entity.  How do I batch update?  Also, how do I make sure that only the fields I change are updated?”

The answer is that you basically have to combine your crmsvcutil.exe generated code with ExecuteMultipleResults.  Here’s an example:

var conn = CrmConnection.Parse("USE A VALID connection string using appropriate format documented at https://msdn.microsoft.com/en-us/library/jj602970.aspx");
var ctx = new marcsctest1Context(new OrganizationService(conn));

// NOTE: The query below uses LINQ projection.  The CRM LINQ provider will translate this to a query that only returns ID & Name
var query = 
    from a in ctx.AccountSet
    select new Account
    {
        Id = a.Id,
        Name = a.Name
    };

var executeMultipleRequest = new ExecuteMultipleRequest()
{
    Settings = new ExecuteMultipleSettings(){
        ContinueOnError = false,
        ReturnResponses = true
    },
    Requests = new OrganizationRequestCollection()
};

foreach (var account in query)
{
    account.Name += " - Updated";
    //UpdateObject is required to set the EntityState to Changed because it is readonly through crmsvcutil generated entities
    ctx.UpdateObject(account); 

    executeMultipleRequest.Requests.Add(new UpdateRequest()
    {
        Target = account
    });
}

//Don't forget to check response.IsFaulted and handle appropriately
var response = ctx.Execute(executeMultipleRequest) as ExecuteMultipleResponse;

@devkeydet

Using LINQPad with the CRM Online OData service

I’ve been a longtime fan of LINQPad (www.linqpad.net) as a general purpose tool for executing LINQ queries with various LINQ enabled technologies as well as a general purpose scratchpad for testing out .NET code without having to fire up Visual Studio.  I’ve already blogged about how to use LINQPad to work with the CRM Online SOAP service:

http://blogs.msdn.com/b/devkeydet/archive/2012/12/04/linqpad-crm-2011-and-using-office-365-accounts.aspx

One thing that may not be obvious is how to use LINQPad to query the OData service that comes with Dynamics CRM Online.  Using the same basic concept that I showed with the SOAP service, I created a video walkthrough of how to interact with the OData service from LINQPad:

 

Here’s the LINQPad starter code I showed in the video:

var clientId = "[YOUR_CLIENT_ID]";
var resource = "https://[YOUR_INSTANCE].crm.dynamics.com";
var redirectUri = new Uri("http://linqpad"); //replace with your redirect uri

var authContext = new AuthenticationContext("https://login.windows.net/common/oauth2/authorize", false);
var authResult = authContext.AcquireToken(resource, clientId, redirectUri, PromptBehavior.Auto);
Util.ClearResults();

var ctx = new marcsctest1Context(new Uri(resource + "/XRMServices/2011/OrganizationData.svc/"));

ctx.SendingRequest2 +=
 (o, eventArgs) => eventArgs.RequestMessage.SetHeader("Authorization", "Bearer " + authResult.AccessToken);

var query = 
     from a in ctx.AccountSet
     where a.Name.Contains("sample")
     select new
     {
          a.AccountId,
          a.Name,
          a.Address1_City,
          a.Address1_StateOrProvince
     };

query.ToString().Dump("OData Query Url");
query.Dump("Query Results");

One of the things I did, after creating the video, was to write a reusable helper method in the LINQPad MyExtensions class so I can reuse the code to get the access token across multiple LINQPad query sessions.  Here’s the code for the extension:

void Main()
{
     // Write code to test your extensions here. Press F5 to compile and run.
}

public static class MyExtensions
{
     // Write custom extension methods here. They will be available to all queries.
     static string LINQPadAccessToken = null;
     
     public static string GetAccessToken()
     {
          if (LINQPadAccessToken != null)
          {
               return LINQPadAccessToken;
          }
          
          var clientId = "[YOUR_CLIENT_ID]";
          var resource = "https://[YOUR_INSTANCE].crm.dynamics.com";
          var redirectUri = new Uri("http://linqpad"); //your redirect uri

          var authContext = new AuthenticationContext("https://login.windows.net/common/oauth2/authorize", false);
          var authResult = authContext.AcquireToken(resource, clientId, redirectUri, PromptBehavior.Auto);
          Util.ClearResults();
          
          LINQPadAccessToken = authResult.AccessToken;
          
          return LINQPadAccessToken;
     }     
}

Here’s a version of the code in my query tab that is simplified, after writing and leveraging the helper method:

var ctx = new marcsctest1Context(
     new Uri("https://[YOUR_INSTANCE].crm.dynamics.com/XRMServices/2011/OrganizationData.svc/")
);
ctx.SendingRequest2 += 
     (o, eventArgs) => eventArgs.RequestMessage.SetHeader("Authorization", "Bearer " + MyExtensions.GetAccessToken());

var query =      
     from a in ctx.AccountSet
        where a.Name.Contains("sample")
     select new
     {
          a.AccountId,
          a.Name,
          a.Address1_City,
          a.Address1_StateOrProvince
     };

query.ToString().Dump("OData Query Url");
query.Dump("Query Results");

Note the call to MyExtensions.GetAccessToken() above.  You could obviously refactor the GetAccessToken() method more to make it even more reusable, but I will leave that as an exercise for you.

This approach will become even more powerful once Dynamics CRM introduces the new OData v4 service endpoint:

https://msdn.microsoft.com/en-us/dynamics/crm/webapipreview

As I mention in the video, once that happens, you’ll want to perform the codgen with the OData Client Code Generator instead of “Add Service Reference”:

http://blogs.msdn.com/b/odatateam/archive/2014/03/11/how-to-use-odata-client-code-generator-to-generate-client-side-proxy-class.aspx

@devkeydet

Setting up a Microsoft Cloud trial

CRM Online based solutions often run across the broader Microsoft Cloud, not just CRM Online alone.  As they say, a picture is worth a thousand words.  So here’s a picture that hits home this point at a high level.

image

To help people get started trying this environment out, I’ve created a video that walks you through setting up a trial for CRM Online, Office 365, and Microsoft Azure where all the services are provisioned for Single Sign On (SSO) under a single Azure Active Directory tenant and provide shared administration. 

@devkeydet