<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<title type="text">Nana Lakshmanan</title>
<generator uri="https://github.com/jekyll/jekyll">Jekyll</generator>
<link rel="self" type="application/atom+xml" href="http://nanalakshmanan.github.io/feed.xml" />
<link rel="alternate" type="text/html" href="http://nanalakshmanan.github.io" />
<updated>2018-03-01T02:05:20+00:00</updated>
<id>http://nanalakshmanan.github.io/</id>
<author>
  <name>Nana Lakshmanan</name>
  <uri>http://nanalakshmanan.github.io/</uri>
  <email>nanalakshmanan@gmail.com</email>
</author>


<entry>
  <title type="html"><![CDATA[Targetting Automation Executions against Resource Groups]]></title>
  <link rel="alternate" type="text/html" href="http://nanalakshmanan.github.io/blog/Target-ResourceGroup/" />
  <id>http://nanalakshmanan.github.io/blog/Target-ResourceGroup</id>
  <published>2017-12-15T00:00:00+00:00</published>
  <updated>2017-12-15T00:00:00+00:00</updated>
  <author>
    <name>Nana Lakshmanan</name>
    <uri>http://nanalakshmanan.github.io</uri>
    <email>nanalakshmanan@gmail.com</email>
  </author>
  <content type="html">
    &lt;p&gt;This blog explains targetting Systems Manager Automation Executions against Resource Groups.&lt;/p&gt;

&lt;h1 id=&quot;resource-groups&quot;&gt;Resource Groups&lt;/h1&gt;

&lt;p&gt;&lt;a href=&quot;https://aws.amazon.com/systems-manager/&quot;&gt;AWS Systems Manager&lt;/a&gt; introduces the concept of Resource Groups. &lt;a href=&quot;https://aws.amazon.com/systems-manager/features/&quot;&gt;Resource Groups&lt;/a&gt; are a way to create a logical group of resources. Resource Groups are living queries based on tag conditions. It is a &lt;strong&gt;query&lt;/strong&gt; because it represents a filtered set of resource instances (&lt;em&gt;of same or different resource types&lt;/em&gt;) from your environment based on a set of tag based conditions and it is &lt;strong&gt;living&lt;/strong&gt; because the system periodically refreshes this filtered list.&lt;/p&gt;

&lt;p&gt;For instance, if you create a Resource Group representing an Auto Scaling Group, then the Resource group will contain instances in the ASG at any given point in time. Depending on various factors the number of instances in an ASG will vary. This gets reflected in the number of instances in a Resource Group. A more complex example of a resource group can represent all resources in your HR application including EC2 instance, S3 buckets, EBS volumes, etc.&lt;/p&gt;

&lt;p&gt;A Resource group can therefore be used to represent all resources associated with a particular workload such as different layers of an application stack, or production versus development environments, etc.&lt;/p&gt;

&lt;h1 id=&quot;executing-automation-targetting-resource-groups&quot;&gt;Executing Automation targetting Resource Groups&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Target Type&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Automation Documents can be executed against a Resource Group. When a resource group contains resources of different types (EC2 instances, S3 buckets, etc) what exactly does targetting a resource group mean. Let us take a closer look at the same.&lt;/p&gt;

&lt;p&gt;Automation Documents now support defining a target type. This implies what type of resources the execution of this document targets. The target type can be viewed using the following AWS CLI&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;aws ssm list-documents &lt;span class=&quot;nt&quot;&gt;--filters&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Key=DocumentType, Values=Automation'&lt;/span&gt;                
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Here is a sample&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;TargetType&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;/AWS::EC2::Instance&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; 
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AWS-TerminateEC2Instance&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; 
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;PlatformTypes&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Windows&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; 
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Linux&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; 
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;DocumentVersion&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; 
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;DocumentType&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Automation&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; 
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Owner&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Amazon&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; 
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The PowerShell equivalent of the same is&lt;/p&gt;

&lt;div class=&quot;language-powershell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$Filter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;New-Object &lt;/span&gt;Amazon.SimpleSystemsManagement.Model.DocumentKeyValuesFilter                
&lt;span class=&quot;nv&quot;&gt;$Filter&lt;/span&gt;.Key&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'DocumentType'&lt;/span&gt; 
&lt;span class=&quot;nv&quot;&gt;$Filter&lt;/span&gt;.Values&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'Automation'&lt;/span&gt;
Get-SSMDocumentList -Filter &lt;span class=&quot;nv&quot;&gt;$Filter&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; &lt;code class=&quot;highlighter-rouge&quot;&gt;TargetType&lt;/code&gt; is not a mandatory parameter and only one target type can be specified for an automation document.&lt;/p&gt;

&lt;p&gt;The values for &lt;code class=&quot;highlighter-rouge&quot;&gt;TargetType&lt;/code&gt; are the same as defined by AWS Cloudformation. All resource type definitions can be found &lt;a href=&quot;https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html&quot;&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution targetting Resource Groups&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When an automation execution is targetted against a resource group, the Automation service will filter the resources from the resource group based on the target type of the automation document. It then applies rate control (&lt;em&gt;execute against N at a time&lt;/em&gt;) for automation executions against these filtered set of resources. For instance, for the Automation document &lt;code class=&quot;highlighter-rouge&quot;&gt;AWS-StopEC2Instance&lt;/code&gt;, the target type is &lt;code class=&quot;highlighter-rouge&quot;&gt;/AWS::EC2::Instance&lt;/code&gt;. When this document is executed against a resource group, Automation service will filter all EC2 instances from the resource group, apply rate control and execute the automation.&lt;/p&gt;

&lt;p&gt;Note that when no target type is defined on the document, there will be no filtering and the execution will be against all resources in the resource group.&lt;/p&gt;

&lt;p&gt;Executing an automation document against a resource group can be invoked using the following AWS CLI&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;aws ssm start-automation-execution &lt;span class=&quot;nt&quot;&gt;--document-name&lt;/span&gt; AWS-StopEC2Instance &lt;span class=&quot;nt&quot;&gt;--targets&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;Key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;ResourceGroup,Values&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;resource-group-1 &lt;span class=&quot;nt&quot;&gt;--target-parameter-name&lt;/span&gt; InstanceId
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;Key=ResourceGroup&lt;/code&gt; indicates that the targetting is against a Resource Group&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;Values=resource-group-1&lt;/code&gt; indicates the value of the resource group that is being targetted&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;target-parameter-name InstanceId&lt;/code&gt; indicates the name of the parameter in the Automation document on which the targetting happens&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The PowerShell equivalent of the same is below&lt;/p&gt;

&lt;div class=&quot;language-powershell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$target&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;New-Object &lt;/span&gt;Amazon.SimpleSystemsManagement.Model.Target                                                                              
&lt;span class=&quot;nv&quot;&gt;$target&lt;/span&gt;.Key&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'ResourceGroup'&lt;/span&gt;                                                                                                                   
&lt;span class=&quot;nv&quot;&gt;$target&lt;/span&gt;.Values&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'resource-group-1'&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;Start&lt;/span&gt;-SSMAutomationExecution -DocumentName &lt;span class=&quot;s1&quot;&gt;'AWS-StopEC2Instance'&lt;/span&gt; -Target &lt;span class=&quot;nv&quot;&gt;$target&lt;/span&gt; -TargetParameterName &lt;span class=&quot;s1&quot;&gt;'InstanceId'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

    &lt;p&gt;&lt;a href=&quot;http://nanalakshmanan.github.io/blog/Target-ResourceGroup/&quot;&gt;Targetting Automation Executions against Resource Groups&lt;/a&gt; was originally published by Nana Lakshmanan at &lt;a href=&quot;http://nanalakshmanan.github.io&quot;&gt;Nana Lakshmanan&lt;/a&gt; on December 15, 2017.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[PassRole permissions and Embedded AssumeRole in Automation Documents]]></title>
  <link rel="alternate" type="text/html" href="http://nanalakshmanan.github.io/blog/Embedded-Assume-Role/" />
  <id>http://nanalakshmanan.github.io/blog/Embedded-Assume-Role</id>
  <published>2017-12-04T00:00:00+00:00</published>
  <updated>2017-12-04T00:00:00+00:00</updated>
  <author>
    <name>Nana Lakshmanan</name>
    <uri>http://nanalakshmanan.github.io</uri>
    <email>nanalakshmanan@gmail.com</email>
  </author>
  <content type="html">
    &lt;p&gt;This blog explains how to embed AssumeRole in Automation documents and not require PassRole permissions.&lt;/p&gt;

&lt;p&gt;AWS Systems Manager Automation is used to automate common maintenance and deployment tasks targetting various AWS resources. Automations are defined using Automation Documents. You can view a list of available Automation documents using the following CLI&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;aws ssm list-documents &lt;span class=&quot;nt&quot;&gt;--filters&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Key=DocumentType, Values=Automation'&lt;/span&gt;                
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The PowerShell equivalent of the same is&lt;/p&gt;

&lt;div class=&quot;language-powershell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$Filter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;New-Object &lt;/span&gt;Amazon.SimpleSystemsManagement.Model.DocumentKeyValuesFilter                
&lt;span class=&quot;nv&quot;&gt;$Filter&lt;/span&gt;.Key&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'DocumentType'&lt;/span&gt; 
&lt;span class=&quot;nv&quot;&gt;$Filter&lt;/span&gt;.Values&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'Automation'&lt;/span&gt;
Get-SSMDocumentList -Filter &lt;span class=&quot;nv&quot;&gt;$Filter&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In most Automation documents, you will find the following:&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;s2&quot;&gt;&quot;assumeRole&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;{{ AutomationAssumeRole }}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;parameters&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AutomationAssumeRole&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;String&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;description&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;(Optional) The ARN of the role that allows Automation to  perform the actions on your behalf.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;default&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;                    
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;AssumeRole&lt;/code&gt; essentially is an IAM service role that lets the Automation execution perform actions on AWS resources when the user invoking the same has restricted or no access to the same. Automation expects that you pass the ARN of an IAM role for this parameter.&lt;/p&gt;

&lt;p&gt;One aspect to note is that a user should have &lt;code class=&quot;highlighter-rouge&quot;&gt;PassRole&lt;/code&gt; permission to the role being passed. 
The permissions associated with the role will have something like the following&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Version&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;2012-10-17&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Statement&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Action&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;iam:PassRole&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Resource&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;arn:aws:iam::123456789012:role/Nana&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Effect&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Allow&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If a user does not &lt;code class=&quot;highlighter-rouge&quot;&gt;PassRole&lt;/code&gt; permission then  it results in the following error&lt;/p&gt;

&lt;div class=&quot;language-powershell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;One or more errors occurred. &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;User: arn:aws:iam::123456789012:user/NanaNoPassRole is not authorized to perform: iam:PassRole on resource: arn:aws:iam::123456789012:role/TestAssumeRole&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is by design and to ensure that a user does not pass a role that the user does not have access to. However, it is not required that the &lt;code class=&quot;highlighter-rouge&quot;&gt;AssumeRole&lt;/code&gt; need to be passed as a parameter even though it is very common to do so.&lt;/p&gt;

&lt;p&gt;Automation provides the ability to embed the &lt;code class=&quot;highlighter-rouge&quot;&gt;AssumeRole&lt;/code&gt;. When embedded in the following format, the user it not required to have &lt;code class=&quot;highlighter-rouge&quot;&gt;PassRole&lt;/code&gt; permissions on the role. (&lt;strong&gt;Note&lt;/strong&gt; The user still needs to have permissions to start automation execution using the document)&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;s2&quot;&gt;&quot;assumeRole&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;arn:aws:iam::123456789012:role/TestAssumeRole&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Automation allows providing Account Id as
&lt;code class=&quot;highlighter-rouge&quot;&gt;
{{global:ACCOUNT_ID}}
&lt;/code&gt;. However, if the &lt;code class=&quot;highlighter-rouge&quot;&gt;AssumeRole&lt;/code&gt; is specified in this format, then &lt;code class=&quot;highlighter-rouge&quot;&gt;PassRole&lt;/code&gt; permission is required.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;http://nanalakshmanan.github.io/blog/Embedded-Assume-Role/&quot;&gt;PassRole permissions and Embedded AssumeRole in Automation Documents&lt;/a&gt; was originally published by Nana Lakshmanan at &lt;a href=&quot;http://nanalakshmanan.github.io&quot;&gt;Nana Lakshmanan&lt;/a&gt; on December 04, 2017.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Thank You Microsoft...]]></title>
  <link rel="alternate" type="text/html" href="http://nanalakshmanan.github.io/articles/thank-you-microsoft/" />
  <id>http://nanalakshmanan.github.io/articles/thank-you-microsoft</id>
  <published>2017-01-21T12:08:50+00:00</published>
  <updated>2017-01-21T12:08:50+00:00</updated>
  <author>
    <name>Nana Lakshmanan</name>
    <uri>http://nanalakshmanan.github.io</uri>
    <email>nanalakshmanan@gmail.com</email>
  </author>
  <content type="html">
    &lt;p&gt;…for the amazing memories.&lt;/p&gt;

&lt;p&gt;Back in November 2005, I relocated from India to work at Microsoft on a project code named
&lt;a href=&quot;http://www.jsnover.com/Docs/MonadManifesto.pdf&quot;&gt;&lt;strong&gt;Monad&lt;/strong&gt;&lt;/a&gt;.It was a wonderful journey of 11 memorable years. Journey that
was filled with oppurtunities. I could participate in efforts that were forefront in the company as well as in the
industry. When people told me stories about how our work transformed their lives it was such a delight. One other
aspects that I loved about my time at Microsoft was the brilliant minds that I got to work with. Many are well regarded
in the industry and it was an experience collaborating with them. I also learnt a lot - how to appreciate little things, 
how to value diverse perspectives, how to bounce back from failures, what does it take to be a true professional, how
to build software, how to build a community… the list is rather long. Most importantly Microsoft also taught me the
importance of giving. During this time, there was always something exciting to look forward to and now 
when I look back this has been an amazing journey.
However, I am in an industry where we all love change. Here is my favorite quote on change from the father and inventor of
&lt;a href=&quot;https://msdn.microsoft.com/powershell&quot;&gt;&lt;strong&gt;PowerShell&lt;/strong&gt;&lt;/a&gt; - &lt;a href=&quot;https://twitter.com/jsnover&quot;&gt;&lt;strong&gt;Jeffrey Snover&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So in the IT profession, we learn new things. If you didn’t want to learn new things, you should get into lumber. 
There has not been a new tree in quite a long time.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;(&lt;a href=&quot;http://snoverisms.com/43-2/&quot;&gt;Source&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;So I have decided to pursue change - an oppurtunity outside of Microsoft. This does not mean that change isn’t possible
at Microsoft. Microsoft as a company has been constantly changing and I am proud of having been through the journey. 
However, cross pollination is good for the industry. That is how I feel we all learn. In fact that is how we also unlearn.
Look at some of the big names at Microsoft. Many of them landed there with a lot of prior experience elsewhere in the industry. Also look at other big
companies. There are many in leadership positions who started their careers at Microsoft. Varied experience and
movement across companies seem to be doing good to the industry. It keeps the HR and Recruting departments busy with
retention and hiring goals as well.&lt;/p&gt;

&lt;p&gt;If you have friends or family from other companies looking for a change or just graduating and looking for an opportunity,
I highly recommend Microsoft as a great place to work. The innovation and culture is something that I have always been 
proud of. Please do stay in touch. Whether it is talking technology, discussing charity or just having a cup of coffee I 
will be delighted to connect. You can follow me on Twitter &lt;a href=&quot;https://twitter.com/NanaLakshmanan&quot;&gt;@nanalakshmanan&lt;/a&gt;&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;http://nanalakshmanan.github.io/articles/thank-you-microsoft/&quot;&gt;Thank You Microsoft...&lt;/a&gt; was originally published by Nana Lakshmanan at &lt;a href=&quot;http://nanalakshmanan.github.io&quot;&gt;Nana Lakshmanan&lt;/a&gt; on January 21, 2017.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[In God We Trust...]]></title>
  <link rel="alternate" type="text/html" href="http://nanalakshmanan.github.io/articles/in-god-we-trust/" />
  <id>http://nanalakshmanan.github.io/articles/in-god-we-trust</id>
  <published>2016-09-22T12:08:50+00:00</published>
  <updated>2016-09-22T12:08:50+00:00</updated>
  <author>
    <name>Nana Lakshmanan</name>
    <uri>http://nanalakshmanan.github.io</uri>
    <email>nanalakshmanan@gmail.com</email>
  </author>
  <content type="html">
    &lt;p&gt;…everyone else must write unit tests.&lt;/p&gt;

&lt;p&gt;In this changing world of services, &lt;a href=&quot;https://en.wikipedia.org/wiki/Unit_testing&quot;&gt;unit testing&lt;/a&gt; has become an often &lt;a href=&quot;https://www.reddit.com/r/programming/comments/1zqjk8/why_most_unit_testing_is_waste/&quot;&gt;debated topic&lt;/a&gt;. The intent of this article is not to join the bandwagon but to enumerate certain good design principles that will help write good unit tests.&lt;/p&gt;

&lt;p&gt;Before starting it is good to provide the context behind why this is being written now and why this matters. There are a lot of quality criteria that are applied to product code - unit tests, design guidelines, style guidelines, performance guidelines, localization guidelines, etc. However, more often than not, test code does not have any quality criteria associated with it. This leads to a number of problems:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;There are random failures which need to be evaluated in every test run&lt;/li&gt;
  &lt;li&gt;Test suites carry forward state making it difficult to run many individually&lt;/li&gt;
  &lt;li&gt;Tests are environment specific causing issues (&lt;em&gt;for instance some tests don’t run in localized builds&lt;/em&gt;)&lt;/li&gt;
  &lt;li&gt;It is difficult to refactor since tests will fail and it is hard to figure out why (&lt;em&gt;though this may sound funny, there have been numerous cases this is the actual reason why people fear refactoring bad code&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In order to avoid those problems, tests must adhere to certain overall quality criteria (&lt;em&gt;as someone in my team liked to call it - tests for tests&lt;/em&gt;). The following are some of the principles that can be applied to test suites - which are a collection of related tests&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Isolated&lt;/strong&gt;
Every test suite should setup the environment it needs. This includes all mocking as well as any global environment settings, temporary state or other artifacts it may need. A good way to ensure if a suite conforms to this is to run the suite in isolation in a clean environment (&lt;em&gt;unlike as part of a full test run&lt;/em&gt;) and check if it succeeds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Cleanup&lt;/strong&gt;&lt;br /&gt;
 Every test suite should cleanup the environment and clear any temporary state/artifacts that it has created. This is to ensure that no other test suite takes an accidental dependency on the same (&lt;em&gt;i.e if another test suite is not isolated, it might still succeed due to the existing environment&lt;/em&gt;). A good way to ensure if a suite conforms to this is to snapshot the environment before and after the test run and compare the same.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Deterministic&lt;/strong&gt;
Test suites should be deterministic - reliable and repeatable. Sometimes tests randomly fail - mostly because they are badly written. For example, if a test waits for a period of time instead of waiting for an event, it might randomly fail depending on the load on a system. Such tests waste precious developer time when they have to determine why tests randomly fail. A quick way to ensure test suites are reliable is to run them a few times in a loop and in a few different environments&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Platform Completeness&lt;/strong&gt;
Test suites should account for the variety of platforms they can run on. For instance many test suites may be expected to run in different versions of Windows like Windows server and Nano Server or may be expected to run cross platform like on Windows and Linux. Tests need to ensure that they are written correctly to accommodate the same. If tests do not belong to a particular platform they have to be skipped. Tests also have to ensure that they use common API sets to ensure they work correctly on all supported platforms. Running tests on all supported platforms using a CI system will help identify suites that are not platform complete quickly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Maintainability&lt;/strong&gt;
This one cannot be emphasized enough. Given that tests never get to production, there is a tendency to not write maintainable test code. Having test suites that are modular and easy to maintain go a long way in enhancing developer productivity. When dealing with open source projects (&lt;em&gt;even non open source projects for that matter&lt;/em&gt;), please remember that other developers will have to extend and contribute to these tests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Coverage&lt;/strong&gt;
Any test suite should have an acceptable level of coverage. What is acceptable varies across various software projects. However, not having enough coverage can often lead to not enough testing. Having good coverage also ensures that refactoring can be done effectively since tests will find any regressions introduced by way of refactoring.&lt;/p&gt;

&lt;p&gt;These are some of the high level guidelines. If there are other important guidelines please feel free to discuss them in the comments.&lt;/p&gt;


    &lt;p&gt;&lt;a href=&quot;http://nanalakshmanan.github.io/articles/in-god-we-trust/&quot;&gt;In God We Trust...&lt;/a&gt; was originally published by Nana Lakshmanan at &lt;a href=&quot;http://nanalakshmanan.github.io&quot;&gt;Nana Lakshmanan&lt;/a&gt; on September 22, 2016.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[ChefConf 2016 Talk]]></title>
  <link rel="alternate" type="text/html" href="http://nanalakshmanan.github.io/blog/ChefConf-2016-Talk/" />
  <id>http://nanalakshmanan.github.io/blog/ChefConf-2016-Talk</id>
  <published>2016-08-11T00:00:00+00:00</published>
  <updated>2016-08-11T00:00:00+00:00</updated>
  <author>
    <name>Nana Lakshmanan</name>
    <uri>http://nanalakshmanan.github.io</uri>
    <email>nanalakshmanan@gmail.com</email>
  </author>
  <content type="html">
    &lt;p&gt;&lt;strong&gt;Writing DSC Resources and using them in Chef for Windows&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Windows management is all about taking advantage of the rich API surface that features and products have to offer. This API surface includes cmdlets, WMI, etc. 
PowerShell is the platform of choice on Windows that binds together these various API surfaces and brings out the best management experience. 
Therefore it is a natural and obvious choice to expose declarative configuration in Windows using PowerShell Desired State Configuration. 
DSC is a platform that allows any management solution to consume its artifacts and Chef on Windows provides an awesome integration. Chef can consume any DSC resource 
and the resources get executed in the context of the DSC agent process providing the best possible use of the API surface as well as desired performance characteristics. 
In my session at ChefConf 2016, I spoke about how to write DSC resources and how to consume them using Chef for Windows. You can watch the video below&lt;/p&gt;

&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/0xzuabifiWM&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;You can download the slides and code &lt;a href=&quot;https://github.com/nanalakshmanan/ChefConf2016&quot;&gt;here&lt;/a&gt;&lt;/p&gt;


    &lt;p&gt;&lt;a href=&quot;http://nanalakshmanan.github.io/blog/ChefConf-2016-Talk/&quot;&gt;ChefConf 2016 Talk&lt;/a&gt; was originally published by Nana Lakshmanan at &lt;a href=&quot;http://nanalakshmanan.github.io&quot;&gt;Nana Lakshmanan&lt;/a&gt; on August 11, 2016.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Historical Job Logs]]></title>
  <link rel="alternate" type="text/html" href="http://nanalakshmanan.github.io/blog/Historical-Job-Logs/" />
  <id>http://nanalakshmanan.github.io/blog/Historical-Job-Logs</id>
  <published>2016-05-12T00:00:00+00:00</published>
  <updated>2016-05-12T00:00:00+00:00</updated>
  <author>
    <name>Nana Lakshmanan</name>
    <uri>http://nanalakshmanan.github.io</uri>
    <email>nanalakshmanan@gmail.com</email>
  </author>
  <content type="html">
    &lt;p&gt;DSC persists the job details on disk in a specific location. This blog explains how to retrieve the contents at a later point.&lt;/p&gt;

&lt;p&gt;This &lt;a href=&quot;http://nanalakshmanan.com/blog/DSC-get-job-details-post-reboot/&quot;&gt;blog&lt;/a&gt; explains how to setup DSC so you can obtain results of a configuration run post a reboot. That is valuable when you want to capture the information post a reboot during a configuration run. However, there are cases when you may want to obtain the results that happened in the past or let the configuration run post a reboot (&lt;em&gt;without a client connected&lt;/em&gt;) and obtain the results later.&lt;/p&gt;

&lt;p&gt;DSC persists all of the log information as JSON files in its configuration status folder based on the job id. A job id is unique for a configuration run, consistency check, etc. You can look at all of the job ids from the configuration status object (returned by &lt;code class=&quot;highlighter-rouge&quot;&gt;Get-DscConfigurationStatus&lt;/code&gt; cmdlet)&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;Get-DscConfigurationStatus | Get-Member

&lt;/code&gt;&lt;/pre&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;   TypeName: 
Microsoft.Management.Infrastructure.CimInstance#root/Microsoft/Windows/DesiredStateConfiguration/MSFT_DSCConfigurationStatus

Name                       MemberType   Definition                                                                                      
----                       ----------   ----------                                                                                      
Clone                      Method       System.Object ICloneable.Clone()                                                                
Dispose                    Method       void Dispose(), void IDisposable.Dispose()                                                      
Equals                     Method       bool Equals(System.Object obj)                                                                  
GetCimSessionComputerName  Method       string GetCimSessionComputerName()                                                              
GetCimSessionInstanceId    Method       guid GetCimSessionInstanceId()                                                                  
GetHashCode                Method       int GetHashCode()                                                                               
GetObjectData              Method       void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serial...
GetType                    Method       type GetType()                                                                                  
DurationInSeconds          Property     uint32 DurationInSeconds {get;}                                                                 
Error                      Property     string Error {get;}                                                                             
HostName                   Property     string HostName {get;}                                                                          
IPV4Addresses              Property     string[] IPV4Addresses {get;}                                                                   
IPV6Addresses              Property     string[] IPV6Addresses {get;}                                                                   
JobID                      Property     string JobID {get;}                                                                             
LCMVersion                 Property     string LCMVersion {get;}                                                                        
Locale                     Property     string Locale {get;}                                                                            
MACAddresses               Property     string[] MACAddresses {get;}                                                                    
MetaConfiguration          Property     CimInstance#Instance MetaConfiguration {get;}                                                   
MetaData                   Property     string MetaData {get;}                                                                          
Mode                       Property     string Mode {get;}                                                                              
NumberOfResources          Property     uint32 NumberOfResources {get;}                                                                 
PSComputerName             Property     string PSComputerName {get;}                                                                    
RebootRequested            Property     bool RebootRequested {get;}                                                                     
ResourcesInDesiredState    Property     CimInstance#InstanceArray ResourcesInDesiredState {get;}                                        
ResourcesNotInDesiredState Property     CimInstance#InstanceArray ResourcesNotInDesiredState {get;}                                     
StartDate                  Property     CimInstance#DateTime StartDate {get;}                                                           
Status                     Property     string Status {get;}                                                                            
Type                       Property     string Type {get;}                                                                              
ToString                   ScriptMethod System.Object ToString();                                                                       

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Here is a way to look at all job ids&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;Get-DscConfigurationStatus -All | Format-Table Status, StartDate, Type, JobId -AutoSize

&lt;/code&gt;&lt;/pre&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Status  StartDate            Type    JobId                                 
------  ---------            ----    -----                                 
Success 5/12/2016 6:35:05 AM Initial {535A36CD-1846-11E6-AD61-8C4019F5FC80}
Success 5/12/2016 6:34:47 AM Initial {4B1F0CB6-1846-11E6-AD61-8C4019F5FC80}

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once you obtain the job id of a specific job you are interested in, you can locate the json files corresponding to it from the configuration status folder&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;$jobid = '{535A36CD-1846-11E6-AD61-8C4019F5FC80}'
dir &quot;$env:windir\system32\configuration\configurationstatus\$jobid*.json&quot;

&lt;/code&gt;&lt;/pre&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    Directory: C:\Windows\system32\configuration\configurationstatus


Mode                LastWriteTime         Length Name                                                                                   
----                -------------         ------ ----                                                                                   
-a----        5/12/2016   6:35 AM           2508 {535A36CD-1846-11E6-AD61-8C4019F5FC80}-0.details.json                                  

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;0&lt;/code&gt; indicates the initial run. The suffix gets incremented post every reboot (*&lt;code class=&quot;highlighter-rouge&quot;&gt;1&lt;/code&gt; after the first reboot and so on).&lt;/p&gt;

&lt;p&gt;The json file has all the contents of the job logs&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;$Contents = Get-Content .\'{535A36CD-1846-11E6-AD61-8C4019F5FC80}-0.details.json' -Raw -Encoding Unicode
ConvertFrom-Json $contents
&lt;/code&gt;&lt;/pre&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;time                         type    message                                                                                                     
----                         ----    -------                                                                                                     
2016-05-12T06:35:05.455-7:00 verbose [NANA-TOUCH]: LCM:  [ Start  Set      ]                                                                     
2016-05-12T06:35:05.503-7:00 verbose [NANA-TOUCH]: LCM:  [ Start  Resource ]  [[File]f]                                                          
2016-05-12T06:35:05.503-7:00 verbose [NANA-TOUCH]: LCM:  [ Start  Test     ]  [[File]f]                                                          
2016-05-12T06:35:05.507-7:00 verbose [NANA-TOUCH]:                            [[File]f] The destination object was found and no action is requ...
2016-05-12T06:35:05.507-7:00 verbose [NANA-TOUCH]: LCM:  [ End    Test     ]  [[File]f]  in 0.0040 seconds.                                      
2016-05-12T06:35:05.507-7:00 verbose [NANA-TOUCH]: LCM:  [ Skip   Set      ]  [[File]f]                                                          
2016-05-12T06:35:05.507-7:00 verbose [NANA-TOUCH]: LCM:  [ End    Resource ]  [[File]f]                                                          
2016-05-12T06:35:05.511-7:00 verbose [NANA-TOUCH]: LCM:  [ End    Set      ]                                                                     
2016-05-12T06:35:05.511-7:00 verbose [NANA-TOUCH]: LCM:  [ End    Set      ]    in  0.0560 seconds.    
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

    &lt;p&gt;&lt;a href=&quot;http://nanalakshmanan.github.io/blog/Historical-Job-Logs/&quot;&gt;Historical Job Logs&lt;/a&gt; was originally published by Nana Lakshmanan at &lt;a href=&quot;http://nanalakshmanan.github.io&quot;&gt;Nana Lakshmanan&lt;/a&gt; on May 12, 2016.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Composite Resources Explained]]></title>
  <link rel="alternate" type="text/html" href="http://nanalakshmanan.github.io/blog/Composite-Resources-Explained/" />
  <id>http://nanalakshmanan.github.io/blog/Composite-Resources-Explained</id>
  <published>2016-05-11T00:00:00+00:00</published>
  <updated>2016-05-11T00:00:00+00:00</updated>
  <author>
    <name>Nana Lakshmanan</name>
    <uri>http://nanalakshmanan.github.io</uri>
    <email>nanalakshmanan@gmail.com</email>
  </author>
  <content type="html">
    &lt;p&gt;Composite configurations come in handy in a lot of scenarios and provide a layer of abstraction on resources. This blog explains composite resources in PowerShell DSC.&lt;/p&gt;

&lt;p&gt;Any configuration in DSC can be exposed as a resource for other configurations to consume. This configuration is called a composite resource. The parameters of the configuration becomes the properties of the resource. Packaging the configuration in a specific way exposes the configuration as a resource.&lt;/p&gt;

&lt;p&gt;Composite resources are identified as such when resources are discovered&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;Get-DscResource -Name WindowsFeatureSet

&lt;/code&gt;&lt;/pre&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ImplementedAs   Name                      ModuleName                     Version    Properties                                        
-------------   ----                      ----------                     -------    ----------                                        
Composite       WindowsFeatureSet         PSDesiredStateConfiguration    1.1        {DependsOn, Name, Ensure, Source...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;They can be used in a configuration like any other resource&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;
configuration test
{
    Import-DscResource -ModuleName PSDesiredStateConfiguration

    WindowsFeatureSet x
    {
        Name   = 'FS-FileServer', 'Hyper-V'
        Ensure = 'Present'
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Though composite resources can be used in configuration, on compilation, the composite resource - which is a configuration in itself - gets compiled to its resources. If we compile the above configuration, this is how the contents of the configuration file looks like&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/*
@TargetNode='localhost'
@GeneratedBy=nanalakshmanan
@GenerationDate=05/11/2016 11:35:42
@GenerationHost=NANA-TOUCH
*/

instance of MSFT_RoleResource as $MSFT_RoleResource1ref
{
 ResourceID = &quot;[WindowsFeature]Resource0::[WindowsFeatureSet]x&quot;;
 Ensure = &quot;Present&quot;;
 SourceInfo = &quot;::2::1::WindowsFeature&quot;;
 Name = &quot;FS-FileServer&quot;;
 ModuleName = &quot;PSDesiredStateConfiguration&quot;;
 ModuleVersion = &quot;1.0&quot;;
 ConfigurationName = &quot;test&quot;;
};

instance of MSFT_RoleResource as $MSFT_RoleResource2ref
{
 ResourceID = &quot;[WindowsFeature]Resource1::[WindowsFeatureSet]x&quot;;
 Ensure = &quot;Present&quot;;
 SourceInfo = &quot;::8::1::WindowsFeature&quot;;
 Name = &quot;Hyper-V&quot;;
 ModuleName = &quot;PSDesiredStateConfiguration&quot;;
 ModuleVersion = &quot;1.0&quot;;
 ConfigurationName = &quot;test&quot;;
};

instance of OMI_ConfigurationDocument
{
 Version=&quot;2.0.0&quot;;
 MinimumCompatibleVersion = &quot;1.0.0&quot;;
 CompatibleVersionAdditionalProperties= {&quot;Omi_BaseResource:ConfigurationName&quot;};
 Author=&quot;nanalakshmanan&quot;;
 GenerationDate=&quot;05/11/2016 11:35:42&quot;;
 GenerationHost=&quot;NANA-TOUCH&quot;;
 Name=&quot;test&quot;;
}

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As you can see, the composite configuration WindowsFeatureSet got compiled and you can find the underlying resource &lt;strong&gt;WindowsFeature&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Since a composite resource is a configuration, it never gets loaded by the LCM. (&lt;em&gt;A configuration needs to be compiled and the resources it calls are the ones that the LCM needs to load&lt;/em&gt;). This is why an &lt;code class=&quot;highlighter-rouge&quot;&gt;Invoke-DscResource&lt;/code&gt; on a composite resource will not work and you should call it on the underlying resource.&lt;/p&gt;


    &lt;p&gt;&lt;a href=&quot;http://nanalakshmanan.github.io/blog/Composite-Resources-Explained/&quot;&gt;Composite Resources Explained&lt;/a&gt; was originally published by Nana Lakshmanan at &lt;a href=&quot;http://nanalakshmanan.github.io&quot;&gt;Nana Lakshmanan&lt;/a&gt; on May 11, 2016.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Import-DscResource Explained]]></title>
  <link rel="alternate" type="text/html" href="http://nanalakshmanan.github.io/blog/Import-DscResource-Explained/" />
  <id>http://nanalakshmanan.github.io/blog/Import-DscResource-Explained</id>
  <published>2016-04-06T00:00:00+00:00</published>
  <updated>2016-04-06T00:00:00+00:00</updated>
  <author>
    <name>Nana Lakshmanan</name>
    <uri>http://nanalakshmanan.github.io</uri>
    <email>nanalakshmanan@gmail.com</email>
  </author>
  <content type="html">
    &lt;p&gt;This blog explains the need for Import-DscResource in a configuration and what happens under the covers&lt;/p&gt;

&lt;p&gt;When we write a &lt;code class=&quot;highlighter-rouge&quot;&gt;configuration&lt;/code&gt; in DSC, often the first statement is to specify which resources to import and from which modules (&lt;em&gt;in PowerShell 4.0, the built-in resources did not require this. Starting PowerShell 5.0 this will now write a warning asking the author to use an Import-DscResource statement&lt;/em&gt;)&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;
Configuration MyServices
{
	Import-DscResource -ModuleName xPSDesiredStateConfiguration
}

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;When a script is parsed and the parser encounters the &lt;code class=&quot;highlighter-rouge&quot;&gt;Import-DscResource&lt;/code&gt; keyword, it then proceeds to identify the resources in the specified modules. In the above piece of code, the parser looks at &lt;code class=&quot;highlighter-rouge&quot;&gt;xPSDesiredStateConfiguration&lt;/code&gt; module and identifies the resources in it.&lt;/p&gt;

&lt;p&gt;It then creates keywords which map to these resources and makes them available within the scope of the configuration block. In our example the following keywords will be generated - &lt;code class=&quot;highlighter-rouge&quot;&gt;xArchive, xDscWebService, xGroup, xPackage, xPSEndpoint, xRegistry, xRemoteFile, xService, xWindowsOptionalFeature, xWindowsProcess&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is what helps an author use those resources in the configuration. They are keywords since they have a special meaning when the configuration is compiled into a mof document. Since they are generated dynamically they are also called as &lt;strong&gt;dynamic keywords&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Given that these resources are discovered during parse time - or at the time when you are authoring a configuration in ISE - it is important that this operation gets done as quickly as possible. This is why dynamic keywords are not generated for all available resources. This also solves the conflict problem - the same resource defined in multiple module or multiple version of the same module.&lt;/p&gt;

&lt;p&gt;DSC resources can be authored in one of the following ways:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;A script based resource using a schema.mof (&lt;em&gt;typically used when a resource needs to work with PowerShell 4.0&lt;/em&gt;)&lt;/li&gt;
  &lt;li&gt;Class based resource (&lt;em&gt;new in PowerShell 5.0 and the recommended way&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A script based resource has the schema.mof file in a specific location relative to the module folder. However a class based resource can be defined in any script file as part of a module. This is why class based resources need to be explicitly exported in &lt;code class=&quot;highlighter-rouge&quot;&gt;DscResourcesToExport&lt;/code&gt; section of the module manifest and be available with the root module - so parsing of PowerShell script files or script module files can be kept to a minimum.&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;http://nanalakshmanan.github.io/blog/Import-DscResource-Explained/&quot;&gt;Import-DscResource Explained&lt;/a&gt; was originally published by Nana Lakshmanan at &lt;a href=&quot;http://nanalakshmanan.github.io&quot;&gt;Nana Lakshmanan&lt;/a&gt; on April 06, 2016.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Understanding RunAs in DSC]]></title>
  <link rel="alternate" type="text/html" href="http://nanalakshmanan.github.io/blog/Understanding-RunAs/" />
  <id>http://nanalakshmanan.github.io/blog/Understanding-RunAs</id>
  <published>2016-03-18T00:00:00+00:00</published>
  <updated>2016-03-18T00:00:00+00:00</updated>
  <author>
    <name>Nana Lakshmanan</name>
    <uri>http://nanalakshmanan.github.io</uri>
    <email>nanalakshmanan@gmail.com</email>
  </author>
  <content type="html">
    &lt;p&gt;DSC runs configurations in the System context. This blog explains why and how to change the same.&lt;/p&gt;

&lt;p&gt;The DSC Agent - also called the &lt;strong&gt;LocalConfigurationManager (LCM)&lt;/strong&gt; - performs any operation in the &lt;strong&gt;LocalSystem&lt;/strong&gt; context. There are two main reasons as to why it is done this way:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Running something in local system context provides the LCM with necessary privileges to configure the system&lt;/li&gt;
  &lt;li&gt;LCM can proceed after a system reboot without requiring an interactive user session or saving user credentials (&lt;em&gt;which is needed to run as a specified user context&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However the downside of the above is that the LCM cannot perform any operation that requires access to user specific resources like the users profile or registry key or a specific operation that needs to be performed in a user context. This is fine in most of the configuration scenarios. However there are a few that does require access to these resources or require to be run as a specific user (&lt;em&gt;example: some operations in SharePoint configuration need to run as the SharePoint setup account&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;DSC supports running as a specific user at a resource level. What this means is, it is possible to specify that a particular resource in a configuration needs to be run in a specific user context by specifying the user credentials. This is done by specifying the credentials against the &lt;strong&gt;PsDscRunAsCredential&lt;/strong&gt; property which is available for all PowerShell resources (&lt;em&gt;similar to DependsOn&lt;/em&gt;)&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;
    xSPManagedAccount xSharePoint 
    { 
        AccountName          = $ServicePoolManagedAccount.UserName 
        Account              = $ServicePoolManagedAccount 
        PsDscRunAsCredential = $SPSetupAccount 
        DependsOn            = $FarmWaitTask 
    } 

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;When a resource is specified to run under a user context, LCM creates a process with the users token (&lt;strong&gt;using PowerShell remoting to the localhost&lt;/strong&gt;) and runs the resource within the context of that process. Since LCM has already created the context the resource doesn’t have access to the Credentials of the user specified. However the resource can get access to the UserName of the credentials as under:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Script resource (using schema.mof): $PsDscContext.RunAsUser&lt;/li&gt;
  &lt;li&gt;Class based resource : $global:PsDscContext.RunAsUser&lt;/li&gt;
&lt;/ul&gt;


    &lt;p&gt;&lt;a href=&quot;http://nanalakshmanan.github.io/blog/Understanding-RunAs/&quot;&gt;Understanding RunAs in DSC&lt;/a&gt; was originally published by Nana Lakshmanan at &lt;a href=&quot;http://nanalakshmanan.github.io&quot;&gt;Nana Lakshmanan&lt;/a&gt; on March 18, 2016.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Setting up a Simple File share based Module Repository for DSC configurations]]></title>
  <link rel="alternate" type="text/html" href="http://nanalakshmanan.github.io/blog/Push-Config-Pull-Module/" />
  <id>http://nanalakshmanan.github.io/blog/Push-Config-Pull-Module</id>
  <published>2016-03-05T00:00:00+00:00</published>
  <updated>2016-03-05T00:00:00+00:00</updated>
  <author>
    <name>Nana Lakshmanan</name>
    <uri>http://nanalakshmanan.github.io</uri>
    <email>nanalakshmanan@gmail.com</email>
  </author>
  <content type="html">
    &lt;p&gt;This blog explains how to set up a simple file share based repository for DSC to install required modules for a configuration.&lt;/p&gt;

&lt;p&gt;In PowerShell 5.0, DSC can pull down modules as required from a repository even when a configuration is pushed (&lt;em&gt;delivered via Start-DscConfiguration&lt;/em&gt;). This is especially useful in scenarios when you do not want to setup a pull server. This method also eliminates the module deployment problem in the &lt;code class=&quot;highlighter-rouge&quot;&gt;Push&lt;/code&gt; mode.&lt;/p&gt;

&lt;p&gt;Let us walk through the whole process using a simple example. Here is a simple configuration that uses a resource downloaded from the &lt;a href=&quot;http://www.powershellgallery.com/&quot;&gt;PowerShell gallery&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;configuration Sample
{
    Import-DscResource -ModuleName xPSDesiredStateConfiguration

    xArchive SampleArchive
    {
        Path             = 'D:\Nana\TempContents'
        Destination      = 'D:\Nana\official\temp\tempcontents.zip'
        CompressionLevel = 'Fastest'
        DestinationType  = 'File'
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The above configuration requires the &lt;code class=&quot;highlighter-rouge&quot;&gt;xPSDesiredStateConfiguration&lt;/code&gt; module on the target node in order to enact the configuration.&lt;/p&gt;

&lt;p&gt;In PowerShell 4.0, if the configuration &lt;code class=&quot;highlighter-rouge&quot;&gt;RefreshMode&lt;/code&gt; is &lt;code class=&quot;highlighter-rouge&quot;&gt;Push&lt;/code&gt; then the module needs to be available in the node (&lt;em&gt;in case of pull, it can pull down the module&lt;/em&gt;). Let us see how this can be simplified in PowerShell 5.0&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting up File Share&lt;/strong&gt;
The first step in the process is setting up the file share with anonymous access. We can setup the file share using the following cmdlet&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;New-SmbShare -Name DSCShare -Path D:\Nana\Official\DscShare -Description 'File share for DSC modules' -ReadAccess everyone -Verbose

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Making Modules Available&lt;/strong&gt;
Once we have the share setup, we need to ensure that the modules are packaged and made available as required by the DSC pull protocol. These are easily automatable steps and we can see how to achieve the same&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;If you are downloading modules from the PowerShell Gallery (like in this case), save the module to a disk location&lt;/li&gt;
&lt;/ol&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;Find-Module xPSDesiredStateConfiguration | Save-Module -Path D:\Nana\Official\DownloadedModules -Verbose
&lt;/code&gt;&lt;/pre&gt;

&lt;ol&gt;
  &lt;li&gt;Then we need to zip this module as required by DSC pull. Here are a few requirements on the zip structure
    &lt;ul&gt;
      &lt;li&gt;The zip file should be named &lt;ModuleName_Version&gt;.zip. So in our case it needs to be xPSDesiredStateConfiguration_3.7.0.0.zip&lt;/ModuleName_Version&gt;&lt;/li&gt;
      &lt;li&gt;The contents of the module should be at the root level. That simply means the zip file cannot contain a folder 3.7.0.0 but should contain all the contents within it&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We can achieve the above using the following PowerShell cmdlet&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;Compress-Archive -Path D:\Nana\Official\DownloadedModules\xPSDesiredStateConfiguration\3.7.0.0\* -DestinationPath D:\Nana\Official\DscShare\xPSDesiredStateConfiguration_3.7.0.0.zip -Verbose
&lt;/code&gt;&lt;/pre&gt;

&lt;ol&gt;
  &lt;li&gt;Once we have the zip file created, we then need to create its checksum&lt;/li&gt;
&lt;/ol&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;New-DscChecksum -Path D:\Nana\Official\DscShare\xPSDesiredStateConfiguration_3.7.0.0.zip -OutPath D:\Nana\Official\DscShare -Verbose
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Setting up Target Node to Pull Modules&lt;/strong&gt;
Now that we have setup the file share we need to let DSC know that it needs to pull these modules from the share. No surpise that we will do this using the LocalConfigurationManager settings&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;[DscLocalConfigurationManager()]
configuration PushToPull
{
    Settings
    {
        RefreshMode = 'Push'
        # A configuration Id needs to be specified, known bug
        ConfigurationID = '3a15d863-bd25-432c-9e45-9199afecde91'
    }

    ResourceRepositoryShare FileShare
    {
        SourcePath = '\\nana-hyperv2\dscshare\'
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We need to then compile and deliver this to the target node&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;
PushToPull -OutputPath D:\Nana\Official\Temp\pushtopull -Verbose

&lt;/code&gt;&lt;/pre&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    Directory: D:\Nana\Official\Temp\pushtopull


Mode                LastWriteTime         Length Name                                                      
----                -------------         ------ ----                                                      
-a----         3/5/2016  12:54 PM           1818 localhost.meta.mof 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;Set-DscLocalConfigurationManager -Path D:\Nana\Official\Temp\pushtopull -Verbose
&lt;/code&gt;&lt;/pre&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;VERBOSE: Performing the operation &quot;Start-DscConfiguration: SendMetaConfigurationApply&quot; on target &quot;MSFT_DSCLo
calConfigurationManager&quot;.
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendMetaConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer NANA-TOUCH with user sid S-1-5-21-2127521184-1604012920-1887927527-2581743.
VERBOSE: [NANA-TOUCH]: LCM:  [ Start  Set      ]
VERBOSE: [NANA-TOUCH]: LCM:  [ Start  Resource ]  [MSFT_DSCMetaConfiguration]
VERBOSE: [NANA-TOUCH]: LCM:  [ Start  Set      ]  [MSFT_DSCMetaConfiguration]
VERBOSE: [NANA-TOUCH]: LCM:  [ End    Set      ]  [MSFT_DSCMetaConfiguration]  in 0.0400 seconds.
VERBOSE: [NANA-TOUCH]: LCM:  [ End    Resource ]  [MSFT_DSCMetaConfiguration]
VERBOSE: [NANA-TOUCH]: LCM:  [ End    Set      ]
VERBOSE: [NANA-TOUCH]: LCM:  [ End    Set      ]    in  0.0890 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Set-DscLocalConfigurationManager finished in 0.277 seconds.

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Testing pulling down Modules&lt;/strong&gt;
Now that we have everything setup, let us set our setup using the sample configuration at hand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compile the sample in a node that has the xPSDesiredStateConfiguration module&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;Start-DscConfiguration -Path D:\Nana\Official\Temp\sample -Wait -Force -Verbose

&lt;/code&gt;&lt;/pre&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer NANA-TOUCH with user sid S-1-5-21-2127521184-1604012920-1887927527-2581743.
VERBOSE: [NANA-TOUCH]: LCM:  [ Start  Set      ]
VERBOSE: [NANA-TOUCH]:                            [DSCEngine] Module xPSDesiredStateConfiguration_3.7.0.0.zip downloaded.
VERBOSE: [NANA-TOUCH]:                            [DSCEngine] Resource xPSDesiredStateConfiguration version 3.7.0.0 installed.
VERBOSE: [NANA-TOUCH]: LCM:  [ Start  Resource ]  [[xArchive]SampleArchive]
VERBOSE: [NANA-TOUCH]: LCM:  [ Start  Test     ]  [[xArchive]SampleArchive]
VERBOSE: [NANA-TOUCH]:                            [[xArchive]SampleArchive] Test Result True
VERBOSE: [NANA-TOUCH]: LCM:  [ End    Test     ]  [[xArchive]SampleArchive]  in 1.0780 seconds.
VERBOSE: [NANA-TOUCH]: LCM:  [ Skip   Set      ]  [[xArchive]SampleArchive]
VERBOSE: [NANA-TOUCH]: LCM:  [ End    Resource ]  [[xArchive]SampleArchive]
VERBOSE: [NANA-TOUCH]: LCM:  [ End    Set      ]
VERBOSE: [NANA-TOUCH]: LCM:  [ End    Set      ]    in  11.7140 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 12.068 seconds
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

    &lt;p&gt;&lt;a href=&quot;http://nanalakshmanan.github.io/blog/Push-Config-Pull-Module/&quot;&gt;Setting up a Simple File share based Module Repository for DSC configurations&lt;/a&gt; was originally published by Nana Lakshmanan at &lt;a href=&quot;http://nanalakshmanan.github.io&quot;&gt;Nana Lakshmanan&lt;/a&gt; on March 05, 2016.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[New-xSelfSignedDscEncryptionCertificate]]></title>
  <link rel="alternate" type="text/html" href="http://nanalakshmanan.github.io/blog/New-xSelfSignedDscEncryptionCertificate/" />
  <id>http://nanalakshmanan.github.io/blog/New-xSelfSignedDscEncryptionCertificate</id>
  <published>2016-02-29T00:00:00+00:00</published>
  <updated>2016-02-29T00:00:00+00:00</updated>
  <author>
    <name>Nana Lakshmanan</name>
    <uri>http://nanalakshmanan.github.io</uri>
    <email>nanalakshmanan@gmail.com</email>
  </author>
  <content type="html">
    &lt;p&gt;This blog details the New-xSelfSignedDscEncryptionCertificate for generating self signed certificates to support encrypting credentials in a Configuration&lt;/p&gt;

&lt;p&gt;This &lt;a href=&quot;https://blogs.msdn.microsoft.com/powershell/2014/01/31/want-to-secure-credentials-in-windows-powershell-desired-state-configuration/&quot;&gt;blog post&lt;/a&gt; in the official PowerShell team blog talks about how to secure credentials in DSC. There were some limitations of this feature in WMF 4.0 which have been addressed in WMF 5.0. These are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ability to encrypt Credentials of any arbitrary length (and not limited to 121 characters)&lt;/strong&gt;
This was required because the only way to store any secret is in the password field of a PSCredential object. Though passwords may not be that long, there were other information which users had to store in the password field which was encountering this limitation.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Validating if a appropriate certificate is being used&lt;/strong&gt;
A digital certificate is categorized for use in only certain scenarios depending on how the &lt;code class=&quot;highlighter-rouge&quot;&gt;KeyUsage&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;EnhancedKeyUsage&lt;/code&gt; properties have been defined. Previously DSC wasn’t validating these and was using any certificate provided for encryption. Now this has also been fixed. The encryption piece of code in DSC now uses the &lt;code class=&quot;highlighter-rouge&quot;&gt;Protect-CMSMessage&lt;/code&gt; cmdlet - which actually enforces these (&lt;em&gt;which is the right thing to do&lt;/em&gt;). This also means the certificate must meet the following criteria:
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;KeyUsage&lt;/strong&gt; must contain &lt;code class=&quot;highlighter-rouge&quot;&gt;KeyEncipherment&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;DataEncipherment&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;EnhancedKeyUsage&lt;/strong&gt; must specify &lt;code class=&quot;highlighter-rouge&quot;&gt;DocumentEncryption&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Though this makes the system secure it also means the barrier to adopting these features is slightly high. Certificates are inherently hard to deal with. Add in a few more constraints and it makes it all the more difficult. In order to minimize this barrier to entry, here is a simple PowerShell module which can help generate a self signed certificate that meets all the requirements&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;Find-Module -Name xDscUtils -Repository psgallery
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Version    Name                                Type       Repository           Description                                        
-------    ----                                ----       ----------           -----------                                        
0.1        xDSCUtils                           Module     PSGallery            Utilities for DSC   
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can install this using&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;Install-Module -Name xDscUtils -Repository PSGallery -Verbose 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This module provides the following simple cmdlet for generating a self-signed certificate that will help with encrypting Credentials in DSC&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt;New-xSelfSignedDscEncryptionCertificate -EmailAddress nanalakshmanan@gmail.com -ExportFilePath D:\MyCerts
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Hopefully this should minimize the barrier to trying out credential encryption in DSC and limit the use of &lt;code class=&quot;highlighter-rouge&quot;&gt;PSDscAllowPlainTextPassword&lt;/code&gt;&lt;/p&gt;

    &lt;p&gt;&lt;a href=&quot;http://nanalakshmanan.github.io/blog/New-xSelfSignedDscEncryptionCertificate/&quot;&gt;New-xSelfSignedDscEncryptionCertificate&lt;/a&gt; was originally published by Nana Lakshmanan at &lt;a href=&quot;http://nanalakshmanan.github.io&quot;&gt;Nana Lakshmanan&lt;/a&gt; on February 29, 2016.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Converging to a Desired State]]></title>
  <link rel="alternate" type="text/html" href="http://nanalakshmanan.github.io/blog/Converging-to-a-desired-state/" />
  <id>http://nanalakshmanan.github.io/blog/Converging-to-a-desired-state</id>
  <published>2016-02-25T00:00:00+00:00</published>
  <updated>2016-02-25T00:00:00+00:00</updated>
  <author>
    <name>Nana Lakshmanan</name>
    <uri>http://nanalakshmanan.github.io</uri>
    <email>nanalakshmanan@gmail.com</email>
  </author>
  <content type="html">
    &lt;p&gt;This blog explains how DSC attempts to converge to a desired state when a configuration is applied.&lt;/p&gt;

&lt;p&gt;When DSC LocalConfigurationManager (LCM aka the DSC agent) is delivered a configuration document, it is staged as &lt;strong&gt;Pending&lt;/strong&gt; (&lt;em&gt;internally LCM stores this document as pending.mof&lt;/em&gt;). This indicates to the LCM that it needs to work on this configuration until the desired state is reached.  Once the desired state is reached, the document is staged as &lt;strong&gt;Current&lt;/strong&gt; (&lt;em&gt;internally LCM moves this document to current.mof and the existing current.mof as previous.mof&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;A configuration document is a graph with dependencies. When the LCM processes a configuration document, it translates the graph to an ordered list and begins to work on resources starting from the first one. The most important aspect is that this is how the LCM &lt;strong&gt;always&lt;/strong&gt; processes a document - whether it is applying a new configuration or checking the consistency of the system against the current configuration or when it is resuming after a reboot. This is what keeps the model simple. For every resource, the LCM first tests if the resource is in the desired state by calling the Test method on the resource (&lt;em&gt;Test-TargetResource method for mof based resources and Test() method on the class for class based resources&lt;/em&gt;). If the resource is in the desired state, it moves to the next resource. If the resource is not in the desired state, it then calls the Set method to get the resource to the desired state. This is what gives the ability for LCM to effectively resume from where it left off - since the resources already acted upon will not be acted upon again.&lt;/p&gt;

&lt;p&gt;Sometimes the LCM will not be able to get the system to a desired state in one convergence cycle. For example, a &lt;code class=&quot;highlighter-rouge&quot;&gt;WindowsFeature&lt;/code&gt; resource requested a reboot or a source network share for a &lt;code class=&quot;highlighter-rouge&quot;&gt;File&lt;/code&gt; resource was not available. Any time the LCM starts it checks for the presence of a &lt;strong&gt;pending.mof&lt;/strong&gt; which indicates that the system has not reached the desired state - in which case the LCM tries to act on the same. This provides the advantage that any reboots as well as transient errors  (&lt;em&gt;like network share not being available&lt;/em&gt;) are handled and the system reaches the desired state.&lt;/p&gt;

&lt;p&gt;The above also means that LCM keeps attempting to act on a &lt;strong&gt;pending&lt;/strong&gt; configuration so long as there is one. The only way to stop the LCM from acting on one is to remove the configuration document. This can be accomplished using the following cmdlet&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-PowerShell&quot;&gt; Remove-DscConfigurationDocument -Stage Pending 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;If the LCM crashes for whatever reason, the DSC timer process will attempt to restart the LCM for up to 3 times. This provides some resiliency against any transient issues in the LCM&lt;/em&gt;&lt;/p&gt;


    &lt;p&gt;&lt;a href=&quot;http://nanalakshmanan.github.io/blog/Converging-to-a-desired-state/&quot;&gt;Converging to a Desired State&lt;/a&gt; was originally published by Nana Lakshmanan at &lt;a href=&quot;http://nanalakshmanan.github.io&quot;&gt;Nana Lakshmanan&lt;/a&gt; on February 25, 2016.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Hello World]]></title>
  <link rel="alternate" type="text/html" href="http://nanalakshmanan.github.io/articles/helo-world/" />
  <id>http://nanalakshmanan.github.io/articles/helo-world</id>
  <published>2016-02-22T12:08:50+00:00</published>
  <updated>2016-02-22T12:08:50+00:00</updated>
  <author>
    <name>Nana Lakshmanan</name>
    <uri>http://nanalakshmanan.github.io</uri>
    <email>nanalakshmanan@gmail.com</email>
  </author>
  <content type="html">
    &lt;p&gt;The first customary post from a developer…&lt;/p&gt;

&lt;p&gt;The world around us is changing. It is changing faster than ever in history. Being part of technology industry, that also means I keep learning new things to 
keep pace with this ever changing world. That brought me to github and the wonderful world around it. So when I learnt about &lt;a href=&quot;https://pages.github.com/&quot;&gt;GitHub Pages&lt;/a&gt;  I made a note that
I should build a website using the same. The need to blog something forced that day to arrive today. Here is my first ‘Hello World’ post hosted using &lt;a href=&quot;https://pages.github.com/&quot;&gt;GitHub Pages&lt;/a&gt; and
&lt;a href=&quot;http://www.jekyllbootstrap.com/&quot;&gt;Jekyll&lt;/a&gt; (&lt;em&gt;to generate the content&lt;/em&gt;). The theme used for this website is &lt;a href=&quot;https://github.com/mmistakes/so-simple-theme/&quot;&gt;SO Simple&lt;/a&gt;. For authoring this post and others I used &lt;a href=&quot;https://www.microsoft.com/en-us/store/apps/markpad/9wzdncrdcfsb&quot;&gt;MarkPad&lt;/a&gt; from the Windows 10 App store&lt;/p&gt;


    &lt;p&gt;&lt;a href=&quot;http://nanalakshmanan.github.io/articles/helo-world/&quot;&gt;Hello World&lt;/a&gt; was originally published by Nana Lakshmanan at &lt;a href=&quot;http://nanalakshmanan.github.io&quot;&gt;Nana Lakshmanan&lt;/a&gt; on February 22, 2016.&lt;/p&gt;
  </content>
</entry>


<entry>
  <title type="html"><![CDATA[Get DSC Job Streams post Reboot]]></title>
  <link rel="alternate" type="text/html" href="http://nanalakshmanan.github.io/blog/DSC-get-job-details-post-reboot/" />
  <id>http://nanalakshmanan.github.io/blog/DSC-get-job-details-post-reboot</id>
  <published>2016-02-22T00:00:00+00:00</published>
  <updated>2016-02-22T00:00:00+00:00</updated>
  <author>
    <name>Nana Lakshmanan</name>
    <uri>http://nanalakshmanan.github.io</uri>
    <email>nanalakshmanan@gmail.com</email>
  </author>
  <content type="html">
    &lt;p&gt;This blog explains how to get various streams after a DSC node reboots.&lt;/p&gt;

&lt;p&gt;When you execute a DSC configuration, sometimes a reboot may be required. The default behavior of DSC is to wait for the user to explicitly reboot and then proceed automatically post reboot.  You can view the defaults using the following cmdlet&lt;/p&gt;

&lt;div class=&quot;language-powershell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;Get-DscLocalConfigurationManager

&lt;/span&gt;ActionAfterReboot              : ContinueConfiguration
AgentId                        : 29C00365-9860-11E5-9F8A-F4B7E2CC0DA1
AllowModuleOverWrite           : False
CertificateID                  : 
ConfigurationDownloadManagers  : &lt;span class=&quot;o&quot;&gt;{}&lt;/span&gt;
ConfigurationID                : 
ConfigurationMode              : ApplyAndMonitor
ConfigurationModeFrequencyMins : 15
Credential                     : 
DebugMode                      : &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;NONE&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
DownloadManagerCustomData      : 
DownloadManagerName            : 
LCMCompatibleVersions          : &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;1.0, 2.0&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
LCMState                       : PendingConfiguration
LCMStateDetail                 : 
LCMVersion                     : 2.0
StatusRetentionTimeInDays      : 10
PartialConfigurations          : 
RebootNodeIfNeeded             : False
RefreshFrequencyMins           : 30
RefreshMode                    : PUSH
ReportManagers                 : &lt;span class=&quot;o&quot;&gt;{}&lt;/span&gt;
ResourceModuleManagers         : &lt;span class=&quot;o&quot;&gt;{}&lt;/span&gt;
PSComputerName                 : 

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;strong&gt;ActionAfterReboot&lt;/strong&gt; property indicates what DSC would do after a reboot. The &lt;strong&gt;RebootNodeIfNeeded&lt;/strong&gt; property indicates what DSC would do when a configuration requires a reboot.&lt;/p&gt;

&lt;p&gt;In cases where you want to obtain the information from the node post a reboot, set DSC to not proceed after reboot. This can be done by using the following meta configuration sample&lt;/p&gt;

&lt;div class=&quot;language-powershell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;DscLocalConfigurationManager&lt;span class=&quot;o&quot;&gt;()]&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;configuration &lt;/span&gt;Settings
&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    Settings
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        ActionAfterReboot  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'StopConfiguration'&lt;/span&gt;
        RebootNodeIfNeeded &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$false&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Then re-apply the existing configuration using the following command&lt;/p&gt;

&lt;div class=&quot;language-powershell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;Start-DscConfiguration&lt;/span&gt; -Wait -UseExisting -Verbose
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;


    &lt;p&gt;&lt;a href=&quot;http://nanalakshmanan.github.io/blog/DSC-get-job-details-post-reboot/&quot;&gt;Get DSC Job Streams post Reboot&lt;/a&gt; was originally published by Nana Lakshmanan at &lt;a href=&quot;http://nanalakshmanan.github.io&quot;&gt;Nana Lakshmanan&lt;/a&gt; on February 22, 2016.&lt;/p&gt;
  </content>
</entry>

</feed>