Category Archives: SMA

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

Advertisements

Workaround for SMA Runbook build failure

Building a robust master SMA Runbook for your automation solutions will have a high chance of ending up with at least a couple of hundreds of lines of code (and magic!). This runbook will most likely consist of runbook nesting, modular workflows, error-handling and fault tolerance which can make things quite complex. Even for the Powershell Engine itself..

One master Runbook I authored ran into a Workflow compilation error when executing the runbook. This because of the sandboxing technology used in SMA and the error appeared because the sandboxed instance could not find the required assemblies.

The workaround is simple;

Identify and find the missing assemblies, which I did at:

C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll
C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Utility\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.Commands.Utility.dll

And copy them to on all SMA Runbook Workers:

%windir%\System32\WindowsPowershell\v1.0

 

Below is the complete error message found in the Event Log on the SMA Runbook Worker:


Build started 2014-10-16 13:06:31.
__________________________________________________
Project "C:\Users\<SMARunbookWorkerAccount>\AppData\Local\Temp\PSWorkflowCompilation\Workflow_f8de811dc1ff4612b48fe9cc0c69d546\Project\RuntimeProject.csproj" (default targets):

Target GetReferenceAssemblyPaths:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(983,5): warning MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
Done building target "GetReferenceAssemblyPaths" in project "RuntimeProject.csproj".
Target PrepareForBuild:
Creating directory "bin\Release\".
Creating directory "obj\Release\".
Target ResolveAssemblyReferences:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3106: Assembly strong name "C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell.Commands.Utility.dll" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\).
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3106: Assembly strong name "C:\Windows\System32\WindowsPowerShell\v1.0\System.Management.Automation.dll" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\).
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3106: Assembly strong name "C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell.Commands.Utility.dll" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\).
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3106: Assembly strong name "C:\Windows\System32\WindowsPowerShell\v1.0\System.Management.Automation.dll" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\).
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "mscorlib", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "System.Data", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
Done building target "ResolveAssemblyReferences" in project "RuntimeProject.csproj".
Target XamlMarkupCompilePass1:
C:\Users\<SMARunbookWorkerAccount>\AppData\Local\Temp\PSWorkflowCompilation\Workflow_f8de811dc1ff4612b48fe9cc0c69d546\Project\ho5coutk.gts.xaml : error XC1014: Assembly 'Microsoft.PowerShell.Commands.Utility, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' can not be resolved. Please add a reference to this assembly in the project that is being built.
C:\Users\<SMARunbookWorkerAccount>\AppData\Local\Temp\PSWorkflowCompilation\Workflow_f8de811dc1ff4612b48fe9cc0c69d546\Project\onhtvslm.qxx.xaml : error XC1014: Assembly 'Microsoft.PowerShell.Commands.Utility, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' can not be resolved. Please add a reference to this assembly in the project that is being built.
C:\Users\<SMARunbookWorkerAccount>\AppData\Local\Temp\PSWorkflowCompilation\Workflow_f8de811dc1ff4612b48fe9cc0c69d546\Project\rl5vmykt.eca.xaml : error XC1014: Assembly 'Microsoft.PowerShell.Commands.Utility, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' can not be resolved. Please add a reference to this assembly in the project that is being built.
Done building target "XamlMarkupCompilePass1" in project "RuntimeProject.csproj" -- FAILED.

Done building project "RuntimeProject.csproj" -- FAILED.

Build FAILED.

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(983,5): warning MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3106: Assembly strong name "C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell.Commands.Utility.dll" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\).
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3106: Assembly strong name "C:\Windows\System32\WindowsPowerShell\v1.0\System.Management.Automation.dll" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\).
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3106: Assembly strong name "C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell.Commands.Utility.dll" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\).
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3106: Assembly strong name "C:\Windows\System32\WindowsPowerShell\v1.0\System.Management.Automation.dll" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\).
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "mscorlib", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "System.Data", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
C:\Users\<SMARunbookWorkerAccount>\AppData\Local\Temp\PSWorkflowCompilation\Workflow_f8de811dc1ff4612b48fe9cc0c69d546\Project\ho5coutk.gts.xaml : error XC1014: Assembly 'Microsoft.PowerShell.Commands.Utility, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' can not be resolved. Please add a reference to this assembly in the project that is being built.
C:\Users\<SMARunbookWorkerAccount>\AppData\Local\Temp\PSWorkflowCompilation\Workflow_f8de811dc1ff4612b48fe9cc0c69d546\Project\onhtvslm.qxx.xaml : error XC1014: Assembly 'Microsoft.PowerShell.Commands.Utility, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' can not be resolved. Please add a reference to this assembly in the project that is being built.
C:\Users\<SMARunbookWorkerAccount>\AppData\Local\Temp\PSWorkflowCompilation\Workflow_f8de811dc1ff4612b48fe9cc0c69d546\Project\rl5vmykt.eca.xaml : error XC1014: Assembly 'Microsoft.PowerShell.Commands.Utility, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' can not be resolved. Please add a reference to this assembly in the project that is being built.
7 Warning(s)
3 Error(s)

Time Elapsed 00:00:03.05

Powershell User Group Sweden – October 2013 Meeting!

As promised during my session at the Powershell User Group Sweden meet last week I will publish my scripts used in my SMA session. And here they are!

For those of you not attending the meet I had the opportunity to give a super compact lesson in Powershell Workflow to cover the basics. Workflows are after all the foundation of SMA. I gave the attendees an overview of SMA administration. Both in powershell/ISE and the Windows Azure Pack portal!

smaportal

Continue reading

What’s the deal with the Runbooks?

Yup, there’s a difference between runbooks and runbooks. Thank you Microsoft for making it easy for us! Let me break it down for you.

On the Orchestrator’s TechNet page we can find the following text:

Topics include how to write, test, and deploy a runbook with System Center 2012 – Orchestrator.

And on the Service Management Automation (SMA) page we can find this:

You automate your tasks by using runbooks, which run Windows PowerShell commands.

So, same name on two different products. With a tiny little difference thanks to the keyword “PowerShell”. Where Orchestrator runbooks are based on activities, the SMA runbooks are completly based on Powershell. Or to be more specific Powershell workflows.

But is it really two different products? Continue reading