{"id":1981,"date":"2013-11-15T12:21:00","date_gmt":"2013-11-15T12:21:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2013\/11\/15\/hungry-for-more-windows-powershell-desired-state-configuration-resources\/"},"modified":"2019-02-18T13:05:29","modified_gmt":"2019-02-18T20:05:29","slug":"hungry-for-more-windows-powershell-desired-state-configuration-resources","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/hungry-for-more-windows-powershell-desired-state-configuration-resources\/","title":{"rendered":"Hungry for more Windows PowerShell Desired State Configuration Resources?"},"content":{"rendered":"<p><span style=\"font-size: 12pt\">Now that you understand the <\/span><span style=\"font-size: medium\">value and need of <\/span><span style=\"font-size: 12pt\"><a href=\"http:\/\/blogs.msdn.com\/b\/powershell\/archive\/2013\/11\/01\/configuration-in-a-devops-world-windows-powershell-desired-state-configuration.aspx\">Windows PowerShell Desired State <span style=\"font-size: 10pt\">Configuration <\/span>(DSC),<\/a> and how to declaratively express the intent of machine configuration via the <a href=\"http:\/\/blogs.msdn.com\/b\/powershell\/archive\/2013\/11\/05\/understanding-configuration-keyword-in-desired-state-configuration.aspx\">new configuration keyword<\/a>, you might be wondering how the configuration happens.<\/span><\/p>\n<p class=\"MsoCommentText\"><span style=\"font-size: 12pt\"><a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/dn249912.aspx\">Configuration on a machine works because of DSC resources<\/a>. Windows Server 2012 R2 and Windows Management Framework (WMF) 4.0 come with <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/dn249921.aspx\">12 built-in resources<\/a>, but that&rsquo;s not all. Like command extensibility of PowerShell, DSC resources are also extensible&ndash;you can create new DSC resources to fill the gap. <\/span><span style=\"line-height: 107%;font-size: 12pt\">This blog will walk you through the mechanics of DSC resources, and how to create new custom DSC resources.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"line-height: 107%;font-size: 12pt\">The Desired State Configuration (DSC) resource is a PowerShell module that is used to model one or more entities that you want to be in a specific, desired state. In the below example, the DSC resource <strong>WindowsFeature<\/strong> is modeled to install or uninstall server roles such as Hyper-V, BranchCache, etc. on the target machine. <\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: center\" align=\"center\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/30\/2018\/10\/4201.image_29EC81AD.png\"><img decoding=\"async\" style=\"border: 0px currentcolor\" title=\"image\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/30\/2018\/10\/7652.image_thumb_37BEC7A8.png\" alt=\"image\" width=\"508\" height=\"120\" border=\"0\" \/><\/a>&nbsp;<span style=\"line-height: 107%;font-size: 12pt\">&nbsp;<\/span><\/p>\n<h1 class=\"WordSection1\"><span style=\"color: #55a3f9\">Resource naming convention<\/span><\/h2>\n<p class=\"MsoNormal\"><span style=\"line-height: 107%;font-size: 12pt\">All the contents of a DSC resource are packaged in to a single directory, so you can deploy DSC resources by using x-copy. By convention, the directory in which the DSC resource is packaged should have the same name as that of the DSC resource. This package contains the following files:<\/span><\/p>\n<h1 class=\"WordSection1\"><span class=\"Heading1Char\"><span style=\"color: #55a3f9\">Resource definition file<\/span><\/span><\/h2>\n<p class=\"MsoNormal\"><span style=\"font-size: medium\">The resource definition file defines the entity that you want to model. In this definition file, you model the properties of the entity that you want to expose with a CIM class definition. The CIM class should inherit from a base CIM class called <strong>OMI_BaseResource<\/strong>. The definition file has the same name as the CIM class, with a <strong>.schema.mof<\/strong> extension.<\/span><\/p>\n<p><span style=\"font-size: medium\">In the below example, a DSC resource named <strong>MSFT_RoleResource<\/strong> has a CIM class named <strong>MSFT_RoleResource<\/strong> that inherits from <strong>OMI_BaseResource<\/strong> CimClass.<\/span><\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 0.5in\" align=\"left\"><span style=\"line-height: 107%;font-size: 12pt\">class <strong>MSFT_RoleResource<\/strong> : <strong>OMI_BaseResource<\/strong><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 0.5in\" align=\"left\"><span style=\"line-height: 107%;font-size: 12pt\">{<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 0.5in\" align=\"left\"><span style=\"line-height: 107%;font-size: 12pt\">};<\/span><\/p>\n<\/blockquote>\n<h2 class=\"WordSection1\"><span style=\"color: #55a3f9\">Friendly name<\/span><\/h2>\n<p class=\"MsoNormal\"><span style=\"font-size: medium\">You can give a DSC resource a more user-friendly name for simplicity and readability by adding the <strong>FriendlyName<\/strong> attribute to the CIM class; this name represents the contract of the DSC resource. In the below example, <strong>MSFT_RoleResource<\/strong> has the friendly name <strong>WindowsFeature<\/strong>.<\/span><\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 0.5in\"><span style=\"line-height: 107%;font-size: 12pt\">[ClassVersion(&#8220;1.0.0&#8221;), <strong>FriendlyName<\/strong>(&#8220;WindowsFeature&#8221;)] <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 0.5in\"><span style=\"line-height: 107%;font-size: 12pt\">class MSFT_RoleResource : OMI_BaseResource<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 0.5in\"><span style=\"line-height: 107%;font-size: 12pt\">{<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 0.5in\"><span style=\"line-height: 107%;font-size: 12pt\">};<\/span><\/p>\n<\/blockquote>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 0.5in\"><span style=\"line-height: 107%;font-size: 12pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: medium\">If a friendly name is specified for a DSC resource, then the same friendly name must be used in the configuration document to reference the DSC resource. Using the resource name to reference it in the configuration document is not supported. However if the friendly name is not specified in the resource definition file, then the resource name can be used in the configuration document.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"line-height: 107%;font-size: 12pt\">For more information about how resources are used to author the configuration document, refer to the following <a href=\"http:\/\/blogs.msdn.com\/b\/powershell\/archive\/2013\/11\/05\/understanding-configuration-keyword-in-desired-state-configuration.aspx\">previous blog<\/a>.<\/span><\/p>\n<h2 class=\"WordSection1\"><span style=\"color: #55a3f9\">Qualifiers<\/span><\/h2>\n<p class=\"MsoNormal\"><span style=\"font-size: small\">Each<span style=\"line-height: 107%;font-size: 12pt\"> property in a <\/span>CIM class<span style=\"line-height: 107%;font-size: 12pt\"> can have one or more of the following <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa393650(v=vs.85).aspx\">qualifiers<\/a>: Key, Required, Read, and Write. The definition of each qualifier is as follows:<\/span><\/span><\/p>\n<div class=\"WordSection1\">\n<ul>\n<li><span style=\"font-size: medium\">The <strong>Key<\/strong> property is used to uniquely identify the entity that is modeled by the resource. It is a mandatory property, and it must be defined with only one value; it cannot be an array or a collection.<\/span><\/li>\n<\/ul>\n<\/div>\n<ul>\n<li><span style=\"font-size: medium\">The <strong>Required<\/strong> property is not a Key property, but is essential for successful execution of the Get, Set, and Test functionalities of the DSC resource. It is mandatory.<\/span><\/li>\n<li><span style=\"font-size: medium\">The <strong>Write<\/strong> properties are used to pass information and values from the configuration to the Get, Set, and Test functionality of the resource, which is essential for its execution.<\/span><\/li>\n<li><span style=\"font-size: medium\">The <strong>Read<\/strong> properties cannot be specified&nbsp; in the configuration;&nbsp; instead, they are returned as results from the execution of Get functionality.<\/span><\/li>\n<\/ul>\n<p class=\"MsoNormal\"><span style=\"font-size: medium\">The following Resource implementation section provides more details about Get, Set, Test functionality.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: medium\">The following is a sample resource definition file for the resource named <strong>MSFT_RoleResource<\/strong> in <strong>MSFT_RoleResource.schema.mof<\/strong> file:<\/span>&nbsp;<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 1in\"><span style=\"line-height: 107%;font-size: 12pt\">[ClassVersion(&#8220;1.0.0&#8221;), FriendlyName(&#8220;WindowsFeature&#8221;)] <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 1in\"><span style=\"line-height: 107%;font-size: 12pt\">class MSFT_RoleResource : OMI_BaseResource<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 1in\"><span style=\"line-height: 107%;font-size: 12pt\">{<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 1in\"><span style=\"line-height: 107%;font-size: 12pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Key] string Name;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 1in\"><span style=\"line-height: 107%;font-size: 12pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Write] string Ensure;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 1in\"><span style=\"line-height: 107%;font-size: 12pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Read] string DisplayName;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 1in\"><span style=\"line-height: 107%;font-size: 12pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Write,EmbeddedInstance(&#8220;MSFT_Credential&#8221;)] string Credential;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 0pt 1in\"><span style=\"line-height: 107%;font-size: 12pt\">};<\/span>&nbsp;<\/p>\n<\/blockquote>\n<p class=\"MsoNormal\"><span style=\"font-size: medium\">The properties of a resource definition can be a complex object such as <strong>MSFT_Credential<\/strong>, as shown in the example above. <strong>MSFT_Credential<\/strong> is one of the DSC infrastructure CIM classes; it is used for channeling credentials into DSC resources.<\/span><\/p>\n<h2><span style=\"color: #55a3f9\">Resource implementation file<\/span><\/h2>\n<p class=\"MsoNormal\"><span style=\"font-size: medium\">The resource Implementation File (.psm1) is a typical <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/dd878324(v=vs.85).aspx\"><span style=\"line-height: 107%\">Windows PowerShell Module<\/span><\/a> file that implements three methods: Get-TargetResource, Test-TargetResource, and Set-TargetResource. The file has the same name as that of its resource, with a .psm1 extension.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: medium\">In the example below, the DSC resource <strong>MSFT_RoleResource<\/strong> is packaged into a directory called <strong>MSFT_RoleResource<\/strong>. The resource definition file is named <strong>MSFT_RoleResource.schema.mof<\/strong>, and the resource implementation file is named <strong>MSFT_RoleResource.psm1<\/strong>.<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: center;margin-left: 0.25in\" align=\"center\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"text-align: center;margin-left: 0.25in\" align=\"center\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/30\/2018\/10\/4152.image_0524758A.png\"><img decoding=\"async\" style=\"margin: 25px 0px;border: 0px currentcolor\" title=\"image\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/30\/2018\/10\/5633.image_thumb_12F6BB85.png\" alt=\"image\" width=\"658\" height=\"146\" border=\"0\" \/><\/a>&nbsp;<\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\"><span style=\"line-height: 107%;font-size: 12pt\">Localized content can be imported in to the resource implementation file (.psm1) by using the conventional PowerShell script internationalization approach. Refer to the following <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/hh849919.aspx\">MSDN article<\/a> for script internationalization.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"line-height: 107%;font-size: 12pt\">Every DSC resource must expose the following three commands:<\/span><\/p>\n<ul>\n<li><span style=\"font-size: medium\"><strong>Get-TargetResource<\/strong>: Get-TargetResource is used to get the status of the entity modeled by the resource. <\/span><\/li>\n<li><span style=\"font-size: medium\"><strong>Test-TargetResource<\/strong>: Test-TargetResource is used to determine whether the entity modeled by resource is in a desired state or not. <\/span><\/li>\n<li><span style=\"font-size: medium\"><strong>Set-TargetResource<\/strong>: Set-TargetResource is used to verify that the entity modeled by resource is in a desired state. If the entity modeled by the resource is not in the desired state, then the functionality of Set-TargetResource is responsible for putting the entity in the desired state.<\/span><\/li>\n<\/ul>\n<h2><span style=\"color: #55a3f9\">Rules for authoring Get-TargetResource, Set-TargetResource and Test-TargetResource commands<\/span>&nbsp;<\/h2>\n<ul>\n<li><span style=\"font-size: medium\">The <strong>Get-TargetResource<\/strong> function implements all Key properties defined in the resource schema file. If a DSC resource requires the Required and\/or Write properties to successfully fetch the state of the modeled entity, then Required or Write properties can also be in the Get-TargetResource input parameter list, and the values for these properties are propagated to Get-TargetResource during the command execution. <\/span><\/li>\n<li><span style=\"font-size: medium\"><strong>Test-TargetResource<\/strong> and <strong>Set-TargetResource<\/strong> functions implement all the Key, Required and Write properties defined in the resource schema file.<\/span><\/li>\n<li><span style=\"font-size: medium\">The parameters exposed by Get, Set, and Test must all exist in the schema file, and should not contain any parameter that is not defined in the schema file.<\/span><\/li>\n<li><span style=\"font-size: medium\">All Key and Required parameters must be authored as mandatory parameters in the corresponding Get, Set, and Test functions.<\/span><\/li>\n<\/ul>\n<h2><span style=\"color: #55a3f9\">Get-TargetResource<\/span><\/h2>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">A sample Get-TargetResource implemented in a resource implementation file (.psm1) is as follows:<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"color: darkblue;font-family: 'Lucida Console';font-size: 10pt\">function<\/span><span style=\"font-family: 'Lucida Console';font-size: 10pt\"> <span style=\"color: blueviolet\">Get-TargetResource<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">{<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkblue\">param<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp; (&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">parameter<\/span>(Mandatory <span style=\"color: darkgray\">=<\/span> <span style=\"color: orangered\">$true<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">ValidateNotNullOrEmpty<\/span>()<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: teal\">string<\/span><span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$Name<\/span><span style=\"color: darkgray\">,<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">Parameter<\/span>(Mandatory<span style=\"color: darkgray\">=<\/span><span style=\"color: orangered\">$false<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: teal\">System.Management.Automation.PSCredential<\/span><span style=\"color: darkgray\">]<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$Credential<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp; )<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># Add implementation logic to fetch the status of <\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># the entity modeled by the resource<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># Add all feature properties to the hash table<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$getTargetResourceResult<\/span> <span style=\"color: darkgray\">=<\/span> @{<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name <span style=\"color: darkgray\">=<\/span> <span style=\"color: orangered\">$feature<\/span><span style=\"color: darkgray\">.<\/span>Name; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DisplayName <span style=\"color: darkgray\">=<\/span> <span style=\"color: orangered\">$feature<\/span><span style=\"color: darkgray\">.<\/span>DisplayName;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ensure <span style=\"color: darkgray\">=<\/span> <span style=\"color: orangered\">$ensureResult<\/span>;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$getTargetResourceResult<\/span>;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">} <\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">The Get-TargetResource returns the status of the modeled entities in a hash table format. This hash table must contain all properties, including the Read properties (along with their values) that are defined in the resource schema. In the example above, the hash table returned by Get-TargetResource contains <strong>Name<\/strong>, <strong>DisplayName<\/strong> and <strong>Ensure<\/strong> properties, along with their values. These properties also exist in the <strong>MSFT_RoleResource<\/strong> CimClass definition that was authored in the resource definition file shown above.<\/span><\/p>\n<h2><span style=\"color: #55a3f9\">Set-TargetResource<\/span><\/h2>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">A sample Set-TargetResource implemented in a resource implementation file (.psm1) is as follows:<\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"color: darkblue;font-family: 'Lucida Console';font-size: 10pt\">function<\/span><span style=\"font-family: 'Lucida Console';font-size: 10pt\"> <span style=\"color: blueviolet\">Set-TargetResource<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">{&nbsp;&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">CmdletBinding<\/span>(SupportsShouldProcess<span style=\"color: darkgray\">=<\/span><span style=\"color: orangered\">$true<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkblue\">param<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; (&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">parameter<\/span>(Mandatory<span style=\"color: darkgray\">=<\/span><span style=\"color: orangered\">$true<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">ValidateNotNullOrEmpty<\/span>()<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: teal\">string<\/span><span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$Name<\/span><span style=\"color: darkgray\">,<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">parameter<\/span>()<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">ValidateSet<\/span>(<span style=\"color: darkred\">&#8220;Present&#8221;<\/span><span style=\"color: darkgray\">,<\/span> <span style=\"color: darkred\">&#8220;Absent&#8221;<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: teal\">string<\/span><span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$Ensure<\/span> <span style=\"color: darkgray\">=<\/span> <span style=\"color: darkred\">&#8220;Present&#8221;<\/span><span style=\"color: darkgray\">,<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">Parameter<\/span>(Mandatory<span style=\"color: darkgray\">=<\/span><span style=\"color: orangered\">$false<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: teal\">System.Management.Automation.PSCredential<\/span><span style=\"color: darkgray\">]<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$Credential<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; )<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># Add implementation logic to make sure that <\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># the entity modeled by resource is put a desired state.<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">Write-Verbose<\/span> <span style=\"color: darkred\">&#8220;Executing Set-TargetResource functionality.&#8221;<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkblue\">for<\/span> (<span style=\"color: orangered\">$i<\/span> <span style=\"color: darkgray\">=<\/span> <span style=\"color: purple\">1<\/span>; <span style=\"color: orangered\">$i<\/span> <span style=\"color: darkgray\">-le<\/span> <span style=\"color: purple\">100<\/span>; <span style=\"color: orangered\">$i<\/span><span style=\"color: darkgray\">++<\/span> )<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\" align=\"left\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">write-progress<\/span> <span style=\"color: navy\">-activity<\/span> <span style=\"color: darkred\">&#8220;Set execution in Progress&#8221;<\/span> <span style=\"color: navy\">-status<\/span> <span style=\"color: darkred\">&#8220;<\/span><span style=\"color: orangered\">$i<\/span><span style=\"color: darkred\">%&nbsp;&nbsp;&nbsp; Complete:&#8221;<\/span> <span style=\"color: navy\">-percentcomplete<\/span> <span style=\"color: orangered\">$i<\/span>;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">} <\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">&nbsp;<\/span><span style=\"line-height: 107%;font-size: 12pt\">The Set-TargetResource method should not return any result to the calling code.<\/span><span style=\"line-height: 107%;font-size: 12pt\">&nbsp;<\/span><\/p>\n<h3><span style=\"color: #55a3f9\">WhatIf mode<\/span><\/h3>\n<p class=\"MsoNormalCxSpFirst\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">As a best practice, Set-TargetResource should support -WhatIf behavior (WhatIf provides a summary of what action would be taken if Set-TargetResource was executed, without actually performing the command). To support -WhatIf behavior, the <strong>SupportShouldProcess<\/strong> attribute must be set to <strong>True<\/strong> in the cmdlet binding of the Set-TargetResource function, as shown below.<\/span><\/p>\n<blockquote>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"color: darkblue;font-family: 'Lucida Console';font-size: 10pt\">function<\/span><span style=\"font-family: 'Lucida Console';font-size: 10pt\"> <span style=\"color: blueviolet\">Set-TargetResource<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">{&nbsp;&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">CmdletBinding<\/span>(SupportsShouldProcess<span style=\"color: darkgray\">=<\/span><span style=\"color: orangered\">$true<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkblue\">param<\/span><\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;(&nbsp;<\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; )<\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;}<\/span><\/p>\n<\/blockquote>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">In the following example, if Set-TargetResource is executed in WhatIf mode, the description of the operation performed is displayed without actually performing the operation. On the other hand, if Set-TargetResource is executed without adding the -WhatIf parameter, the actual operation is run, and the WhatIf description message is not displayed.<\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"color: darkblue;font-family: 'Lucida Console';font-size: 10pt\">function<\/span><span style=\"font-family: 'Lucida Console';font-size: 10pt\"> <span style=\"color: blueviolet\">Set-TargetResource<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">{&nbsp;&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">CmdletBinding<\/span>(SupportsShouldProcess<span style=\"color: darkgray\">=<\/span><span style=\"color: orangered\">$true<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkblue\">param<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; (&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">parameter<\/span>(Mandatory<span style=\"color: darkgray\">=<\/span><span style=\"color: orangered\">$true<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">ValidateNotNullOrEmpty<\/span>()<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: teal\">string<\/span><span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$Name<\/span><span style=\"color: darkgray\">,<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">parameter<\/span>()<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">ValidateSet<\/span>(<span style=\"color: darkred\">&#8220;Present&#8221;<\/span><span style=\"color: darkgray\">,<\/span> <span style=\"color: darkred\">&#8220;Absent&#8221;<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: teal\">string<\/span><span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$Ensure<\/span> <span style=\"color: darkgray\">=<\/span> <span style=\"color: darkred\">&#8220;Present&#8221;<\/span><span style=\"color: darkgray\">,<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">Parameter<\/span>(Mandatory<span style=\"color: darkgray\">=<\/span><span style=\"color: orangered\">$false<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: teal\">System.Management.Automation.PSCredential<\/span><span style=\"color: darkgray\">]<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$Credential<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; )<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkblue\">if<\/span>(<span style=\"color: orangered\">$PSCmdlet<\/span><span style=\"color: darkgray\">.<\/span>ShouldProcess(<span style=\"color: darkred\">&#8220;Description about what operation would be performed if Set-TargetResource would be executed.&#8221;<\/span>))<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># Add implementation logic to make sure that <\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># the entity modeled by resource is put a desired state.<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">} <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormalCxSpLast\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">For more details about <strong>SupportShould<\/strong> parameters, refer to the following documentation:<\/span><\/p>\n<p class=\"MsoListParagraphCxSpFirst\" style=\"margin: 0in 0in 0pt 0.75in;text-indent: -0.25in\"><span style=\"line-height: 107%;font-family: symbol;font-size: 12pt\">&middot;<span style=\"font: 7pt\/normal 'Times New Roman'\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"line-height: 107%;font-size: 12pt\"><a href=\"http:\/\/msdn.microsoft.com\/en-us\/magazine\/cc163293.aspx\">http:\/\/msdn.microsoft.com\/en-us\/magazine\/cc163293.aspx<\/a> <\/span><\/p>\n<p class=\"MsoListParagraphCxSpLast\" style=\"margin: 0in 0in 0pt 0.75in;text-indent: -0.25in\"><span style=\"line-height: 107%;font-family: symbol;font-size: 12pt\">&middot;<span style=\"font: 7pt\/normal 'Times New Roman'\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"line-height: 107%;font-size: 12pt\"><a href=\"http:\/\/technet.microsoft.com\/en-us\/magazine\/ff677563.aspx\">http:\/\/technet.microsoft.com\/en-us\/magazine\/ff677563.aspx<\/a><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">&nbsp;<\/span><\/p>\n<h3><span style=\"color: #55a3f9\">Reboot Status<\/span><\/h3>\n<p class=\"MsoNormalCxSpFirst\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">If the machine must be restarted for the logic in Set-TargetResource to take effect, the resource can notify the DSC engine to restart the target, by setting the global variable $global:DSCMachineStatus to 1 before exiting Set-TargetResource method. The example below shows how restart-required status can be set in the Set-TargetResource functionality.<\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"color: darkblue;font-family: 'Lucida Console';font-size: 10pt\">function<\/span><span style=\"font-family: 'Lucida Console';font-size: 10pt\"> <span style=\"color: blueviolet\">Set-TargetResource<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">{&nbsp;&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">CmdletBinding<\/span>(SupportsShouldProcess<span style=\"color: darkgray\">=<\/span><span style=\"color: orangered\">$true<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkblue\">param<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; (&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">parameter<\/span>(Mandatory<span style=\"color: darkgray\">=<\/span><span style=\"color: orangered\">$true<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">ValidateNotNullOrEmpty<\/span>()<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: teal\">string<\/span><span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$Name<\/span><span style=\"color: darkgray\">,<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">parameter<\/span>()<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">ValidateSet<\/span>(<span style=\"color: darkred\">&#8220;Present&#8221;<\/span><span style=\"color: darkgray\">,<\/span> <span style=\"color: darkred\">&#8220;Absent&#8221;<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: teal\">string<\/span><span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$Ensure<\/span> <span style=\"color: darkgray\">=<\/span> <span style=\"color: darkred\">&#8220;Present&#8221;<\/span><span style=\"color: darkgray\">,<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">Parameter<\/span>(Mandatory<span style=\"color: darkgray\">=<\/span><span style=\"color: orangered\">$false<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: teal\">System.Management.Automation.PSCredential<\/span><span style=\"color: darkgray\">]<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$Credential<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; )<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># Add implementation logic to make sure <\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># that the entity modeled by resource is <\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># put a desired state.<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># If the machine needs to be rebooted <\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># for the Set logic to take effect, <\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># set the $global:DSCMachineStatus to 1<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">Write-Warning<\/span> <span style=\"color: darkred\">&#8220;A machine reboot would be required.&#8221;<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$global:DSCMachineStatus<\/span> <span style=\"color: darkgray\">=<\/span> <span style=\"color: purple\">1<\/span>; <\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"text-indent: 0.5in;margin-bottom: 0pt\"><span style=\"line-height: 107%;font-family: 'Lucida Console';font-size: 10pt\">} <\/span><\/p>\n<h2><span style=\"color: #55a3f9\">Test-TargetResource<\/span><\/h2>\n<p class=\"MsoNormal\" style=\"background: white;line-height: normal;margin-bottom: 0pt\"><span style=\"font-size: 12pt\">Test-TargetResource should always return a Boolean value of either $true or $false as the result of the test operation. If the entity modeled by the resource is in a desired state, then Test-TargetResource should return $true; if not, it should return $false.<\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">A sample Test-TargetResource implemented in a resource implementation file (.psm1) is as follows:<\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"color: darkblue;font-family: 'Lucida Console';font-size: 10pt\">function<\/span><span style=\"font-family: 'Lucida Console';font-size: 10pt\"> <span style=\"color: blueviolet\">Test-TargetResource<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">{<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkblue\">param<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; (&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">parameter<\/span>(Mandatory <span style=\"color: darkgray\">=<\/span> <span style=\"color: orangered\">$true<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">ValidateNotNullOrEmpty<\/span>()<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: teal\">string<\/span><span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$Name<\/span><span style=\"color: darkgray\">,<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">parameter<\/span>()<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">ValidateSet<\/span>(<span style=\"color: darkred\">&#8220;Present&#8221;<\/span><span style=\"color: darkgray\">,<\/span> <span style=\"color: darkred\">&#8220;Absent&#8221;<\/span>)<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: teal\">string<\/span><span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$Ensure<\/span> <span style=\"color: darkgray\">=<\/span> <span style=\"color: darkred\">&#8220;Present&#8221;<\/span><span style=\"color: darkgray\">,<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: deepskyblue\">Parameter<\/span>()<span style=\"color: darkgray\">]<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">[<\/span><span style=\"color: teal\">System.Management.Automation.PSCredential<\/span><span style=\"color: darkgray\">]<\/span> <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: orangered\">$Credential<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; )<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># Add implementation logic to validate <\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># if the entity modeled by resource is <\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># in a desired state or not.<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># In this example Test-TargetResource is <\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># reporting that the entity modeled by <\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkgreen\"># resource is not in the desired state.<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkblue\">return<\/span> <span style=\"color: orangered\">$false<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0in 0in 0pt 0.5in;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 10pt\">} <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;line-height: normal;margin-bottom: 0pt\"><span style=\"font-size: 12pt\">&nbsp;<\/span><\/p>\n<h2><span style=\"color: #55a3f9\">Propagating messages from resource<\/span><\/h2>\n<p class=\"MsoNormalCxSpFirst\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 107%;font-size: 12pt\">The DSC resource can channel Verbose, Warning, Debug, Error, and Progress messages back to the client side, in appropriate PowerShell message streams. These messages are also collected in the &ldquo;Microsoft-Windows-DSC\/Analytic&rdquo; channel on the target machine.<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<h2><span style=\"color: #55a3f9\">Deployment of DSC resource<\/span><\/h2>\n<p class=\"MsoNormal\"><span style=\"line-height: 107%;font-size: 12pt\">All custom DSC resources should be x-copy deployed to <strong>$env:ProgramFiles\\WindowsPowerShell\\Modules\\&lt;Module Name&gt;\\DSCResources\\&lt;Resource Name&gt;<\/strong>.<\/span><\/p>\n<h2><span style=\"color: #55a3f9\">Resource consumption<\/span><\/h2>\n<p class=\"MsoNormal\"><span style=\"line-height: 107%;font-size: 12pt\">A configuration document is authored to serve as a blueprint of the desired state of the machine. This configuration document contains one or more resources that are modeled to put their corresponding entities in a desired state. For more information about how resources are used to author the configuration document, refer to the <a href=\"http:\/\/blogs.msdn.com\/b\/powershell\/archive\/2013\/11\/05\/understanding-configuration-keyword-in-desired-state-configuration.aspx\">previous blog<\/a><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"line-height: 107%;font-size: 12pt\">For more information about DSC, refer to the following <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/dn249918.aspx\">TechNet documentation<\/a>.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: medium\">I hope I have helped you understand how to create your custom DSC Resource easily, simply by creating a resource definition file, implementing the functionality through Get\/Set\/Test-TargetResource, and then packaging your resource as a PowerShell module.<\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p><span style=\"font-size: medium\">Sharath Gopalappa<\/span><\/p>\n<p><span style=\"font-size: medium\">Software Design Engineer<\/span><\/p>\n<p><span style=\"font-size: medium\">Microsoft<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><em><span style=\"font-size: medium\">Updated on 11\/17\/2013: Fixed the formatting to be uniform through out.<\/span><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now that you understand the value and need of Windows PowerShell Desired State Configuration (DSC), and how to declaratively express the intent of machine configuration via the new configuration keyword, you might be wondering how the configuration happens. Configuration on a machine works because of DSC resources. Windows Server 2012 R2 and Windows Management Framework [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[142,150,248,251,345,348],"class_list":["post-1981","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-desired-state-configuration","tag-dsc","tag-powershell","tag-powershell-4-0","tag-windows-powershell-4-0","tag-windows-powershell-desired-state-configuration"],"acf":[],"blog_post_summary":"<p>Now that you understand the value and need of Windows PowerShell Desired State Configuration (DSC), and how to declaratively express the intent of machine configuration via the new configuration keyword, you might be wondering how the configuration happens. Configuration on a machine works because of DSC resources. Windows Server 2012 R2 and Windows Management Framework [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/1981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=1981"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/1981\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=1981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=1981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=1981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}