<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>vSphereDSC Archives - LucD notes</title>
	<atom:link href="https://www.lucd.info/category/dsc/vspheredsc/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lucd.info/category/dsc/vspheredsc/</link>
	<description>My PowerShell ramblings</description>
	<lastBuildDate>Wed, 08 Apr 2020 11:04:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://www.lucd.info/wp-content/uploads/2018/12/cropped-120px-Tibetan_Dharmacakra-32x32.png</url>
	<title>vSphereDSC Archives - LucD notes</title>
	<link>https://www.lucd.info/category/dsc/vspheredsc/</link>
	<width>32</width>
	<height>32</height>
</image> 
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/><atom:link rel="hub" href="https://websubhub.com/hub"/>	<item>
		<title>vSphereDSC &#8211; Principles of Operation</title>
		<link>https://www.lucd.info/2016/06/07/vspheredsc-principles-operation/</link>
					<comments>https://www.lucd.info/2016/06/07/vspheredsc-principles-operation/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Tue, 07 Jun 2016 18:26:38 +0000</pubDate>
				<category><![CDATA[DSC]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[vSphereDSC]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=5318</guid>

					<description><![CDATA[The &#8220;Principles of Operation&#8221; in the title is in fact just an expensive [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>The &#8220;Principles of Operation&#8221; in the title is in fact just an expensive expression for &#8220;How do I use this stuff ?&#8221;. In this post I will try to show you how you can use the vSphereDSC module, as a user, and as a contributing developer. On the side, it also shows you how you can use these vSphereDSC resources.</p>
<p>The <a href="https://github.com/lucdekens/vSphereDSC" target="_blank" rel="noopener noreferrer">vSphereDSC</a> module contains a set of DSC resources to can be used to configure a <strong>vSphere</strong> environment. These DSC resources can be used against <strong>any vSphere Server</strong>, beit a <strong>vCenter</strong> or an <strong>ESXi</strong> node. On the condition of course that the selected resource is supported on the vSphere Server.</p>
<p style="padding-left: 30px;"><a href="https://www.lucd.info/2016/06/07/vspheredsc-principles-operation/principles/" rel="attachment wp-att-5320"><img fetchpriority="high" decoding="async" class="alignnone wp-image-5320 size-medium" src="https://lucd.info/wp-content/uploads/2016/06/principles-300x194.png" alt="principles" width="300" height="194" srcset="https://www.lucd.info/wp-content/uploads/2016/06/principles-300x194.png 300w, https://www.lucd.info/wp-content/uploads/2016/06/principles.png 425w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>For &#8220;users&#8221; of the vSphereDSC resources, the post will show how to <strong>automate</strong> keeping the <strong>module</strong> up to date and how to manage the life cycle of the <strong>Configuration</strong> files that are build on the <strong>vSphereDSC</strong> resources.</p>
<p>For those of you that want to contribute to the <strong>development</strong> of the vSphereDSC module and it&#8217;s resources, this post will also show how you can <strong>automate</strong> the testing phase. In a first instance through a number of PowerShell <strong>scripts</strong>, in a later phase through the use of a <strong>build server</strong>.</p>
<p><span id="more-5318"></span></p>
<h2>The vSphereDSC module</h2>
<p>The <strong>vSphereDSC</strong> is a module that contains a number of DSC resources, that you can use to configure your vSphere environment. To use the vSphereDSC resources, you will need to install the module on your systems.</p>
<p>The first place where you will need the module, is the station where you create and compile your DSC Configuration files.</p>
<p>The other place depends on which enacting method you select to use. With a <strong>Push</strong> setup, you will have to make sure the DSC Resource module is available on the target node. With a <strong>Pull</strong> setup, you will have to make the DSC Resource module available on the Pull server.</p>
<p>The following schema, which I shamelessly copied from <a href="https://blogs.technet.microsoft.com/privatecloud/2013/08/30/introducing-powershell-desired-state-configuration-dsc/" target="_blank" rel="noopener noreferrer">Introducing PowerShell Desired State Configuration (DSC)</a>, shows a high-lelvel view of both methods.</p>
<p><a href="https://www.lucd.info/2016/06/07/vspheredsc-principles-operation/push-pull/" rel="attachment wp-att-5334"><img decoding="async" class="alignnone wp-image-5334 size-medium" src="https://lucd.info/wp-content/uploads/2016/06/push-pull-300x169.png" alt="push-pull" width="300" height="169" srcset="https://www.lucd.info/wp-content/uploads/2016/06/push-pull-300x169.png 300w, https://www.lucd.info/wp-content/uploads/2016/06/push-pull.png 542w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>There are some good overviews available on these two DSC methods. To name but a few:</p>
<ul>
<li><span title="Getting Started with PowerShell Desired State Configuration (DSC)"><a href="https://mva.microsoft.com/en-US/training-courses/getting-started-with-powershell-desired-state-configuration-dsc--8672?l=ZwHuclG1_2504984382" target="_blank" rel="noopener noreferrer">Getting Started with PowerShell Desired State Configuration (DSC)</a>, an MVA course with <a href="https://twitter.com/jsnover" target="_blank" rel="noopener noreferrer">Jeffrey Snover</a> and <a href="https://twitter.com/theJasonHelmick" target="_blank" rel="noopener noreferrer">Jason Helmick</a><br />
</span></li>
<li><a href="https://msdn.microsoft.com/en-us/powershell/dsc/enactingconfigurations" target="_blank" rel="noopener noreferrer">Enacting configurations</a>, in the <a href="https://msdn.microsoft.com/en-us/powershell/dsc/overview" target="_blank" rel="noopener noreferrer">Windows PowerShell Desired State Configuration Overview</a></li>
<li><a href="https://www.penflip.com/powershellorg/the-dsc-book/blob/master/pushing-configurations.txt" target="_blank" rel="noopener noreferrer">Pushing Configurations</a> and Configuring a Pull Server, both in <a href="https://www.penflip.com/powershellorg/the-dsc-book" target="_blank" rel="noopener noreferrer">The DSC Book</a></li>
<li><a href="https://www.pluralsight.com/blog/software-development/powershell-dsc-pull-server" target="_blank" rel="noopener noreferrer">How to set up your first PowerShell DSC pull server</a> from <a href="https://twitter.com/adbertram" target="_blank" rel="noopener noreferrer">Adam Bertram</a>
<p id="pushing-configurations">
</li>
</ul>
<p>In my development and test environment, I use a Pull Server setup. Most of the scripts and procedures that are provided, are intended for a Pull Server setup. But the actions required for using a Push setup, are mostly the same, and simpler (fewer steps).</p>
<p>And one last remark, before we actually start doing things, I use the <a href="https://blogs.msdn.microsoft.com/powershell/2015/02/18/windows-management-framework-5-0-preview-february-2015-is-now-available/" target="_blank" rel="noopener noreferrer">February 2016 WMF 5 release</a> for creating the vSphereDSC classes.</p>
<h2>Configuration files</h2>
<p>In the vSphereDSC module, you will find a subfolder Configurations, in which there are several sample Configuration files. Let&#8217;s have a closer look at one of these files.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">enum Ensure {
   Absent
   Present
}

$tgtName = 'vEng.local.lab'
$configName = 'vmw'
 
Configuration $configName
{
  param(
  [System.Management.Automation.PSCredential]$Credential
  )

  Import-DscResource -ModuleName vSphereDSC

  Node $AllNodes.NodeName
  {
    $number = 0
    foreach($datacenter in $Node.Datacenters)
    {
      $number++
      $dcName = &quot;Datacenter$number&quot;
      VmwDatacenter $dcName
      {
        Name = $datacenter.DatacenterName
        Path = $datacenter.Path
        Ensure = $datacenter.Ensure
        vServer = $Allnodes.Server
        vCredential = $Allnodes.Credential
      }
    }
  }
}

#region VCSA Account
$vcUser = '&lt;your VCSA user&gt;'
$vcPswd = '&lt;your VCSA user password&gt;'
$sVcCred = @{
  TypeName = 'System.Management.Automation.PSCredential'
  ArgumentList = $vcUser,(ConvertTo-SecureString -String $vcPswd -AsPlainText -Force)
}
$vcCred = New-Object @sVcCred
#endregion

$ConfigData = @{   
  AllNodes = @(
    @{
      NodeName = '*'
      Server = 'vcsa.local.lab'   
      Credential = $vcCred
      PSDscAllowPlainTextPassword=$true
      PSDscAllowDomainUser = $true
    },
    @{
      NodeName = $configName
      Datacenters = @(
        @{
          DatacenterName = 'DC1'
          Path = '/'
          Ensure = [Ensure]::Present
        }
      )
    }
  )  
} 

. &quot;$(Split-Path $MyInvocation.MyCommand.Path)\..\..\Tools\Get-TargetGuid.ps1&quot;
$guid = Get-TargetGuid -TargetName $tgtName

Invoke-Expression  &quot;$($configName) -ConfigurationData `$configData -OutputPath '.\DSC'&quot;

$pullShare = '\\pull\DSCService\Configuration\'
$mof = &quot;.\DSC\$($configName).mof&quot;
$tgtMof = &quot;$pullshare\$guid.mof&quot;

Copy-Item -Path $mof -Destination $tgtMof
New-DSCChecksum $tgtMof -Force

# For testing with Start-DscCOnfiguration
Copy-Item -Path $mof -Destination &quot;.\DSC\$($tgtName.Split('.')[0]).mof&quot;</pre><p></p>
<h3>Annotations</h3>
<p>&nbsp;</p>
<p><strong>Line 1-4</strong>: Enumerations that are used in the vSphereDSC Resources that are used in this Configuration file</p>
<p><strong>Line 6:</strong> The hostname of the vEngine server</p>
<p><strong>Line 7</strong>: The name we give to the Configuration, which will also be the name of the generated MOF file</p>
<p><strong>Line 9-34,46-66</strong>: We separate the &#8220;<strong>What</strong>&#8221; and &#8220;<strong>Where</strong>&#8221; in the Configuration. The &#8220;What&#8221; is in this Configuration the way we define a vSphere Folder. The $ConfigData hash table, is the &#8220;Where&#8221;. See S<a href="https://blogs.msdn.microsoft.com/powershell/2014/01/09/separating-what-from-where-in-powershell-dsc/" target="_blank" rel="noopener noreferrer">eparating &#8220;What&#8221; from &#8220;Where&#8221; in PowerShell DSC</a> for some more information on this subject.</p>
<p><strong>Line 36-44</strong>: In the current version of the vSphereDSC module, credentials still need to be in clear text. I plan to change that later on.</p>
<p><strong>Line 68-69</strong>: The Servers that are managed by the Pull Server, need to be addressed by their unique GUID. I store those in a file, and use a short script to retrieve the GUID from that file.</p>
<p><strong>Line 71</strong>: We &#8220;run&#8221; the Configuration. Note how we pass the Where via the <strong>ConfigurationData</strong> parameter. The resulting MOF file will be stored in a subfolder, named <strong>DSC</strong>, in the current folder.</p>
<p><strong>Line 77</strong>: We copy the MOF file to the Pull server. During the copy, the MOF will be renamed to &lt;GUID&gt;.mof</p>
<p><strong>Line 78</strong>: The Pull server needs to distinguish between successive versions of a Configuration file. For that reason we calculate a checksum file.</p>
<p><strong>Line 81</strong>: We are going to use Start-DscConfiguration to test the Configuration, for that reason we rename the MOF file to the shortname of the vEngine Server. More on that later.</p>
<h2>Apply the Configuration</h2>
<p>Now that we have the MOF file, in the correct format, in place on the Pull Server, we can wait till the LCM on the vEngine Server &#8220;pulls&#8221; the Pull Server again. But we can also speed that up, by forcing the DSC Configuration to run. In the Tools folder, there is a sample script to do just that. The file is named <strong>Test-DscConfiguration.ps1</strong>.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$tgtName = 'vEng.local.lab'

$configName = $tgtName.Split('.')[0]

Start-DscConfiguration -ComputerName $configName -Wait -Verbose -Force -Path .\DSC</pre><p></p>
<p>The <strong>$tgtName</strong> variable is the name of the vEngine Server. We extract the first qualifier from the FQDN. And that was the name we gave to the MOF file in the last line of the previous script (veng.mof). The <a href="https://technet.microsoft.com/en-us/library/dn521623.aspx" target="_blank" rel="noopener noreferrer">Start-DscConfiguration </a>cmdlet will look for a MOF file in the location indicated by <strong>Path</strong>, and it will look for a MOF file with the name that is passed on the <strong>ComputerName</strong> parameter.</p>
<p>When all goes according to plan, you will see the Verbose messages scrolling through on the PS console. Have a look at this sample run in a short demo I recorded for the <a href="http://www.vmug.be/abstracts-24th-vmug-2nd-june-2016/" target="_blank" rel="noopener noreferrer">24th VMUGBe+</a>.</p>
<div style="width: 770px;" class="wp-video"><video class="wp-video-shortcode" id="video-5318-1" width="770" height="483" preload="metadata" controls="controls"><source type="video/mp4" src="https://lucd.info/wp-content/uploads/2016/06/VMUGBe-24-Demo-2.mp4?_=1" /><a href="https://lucd.info/wp-content/uploads/2016/06/VMUGBe-24-Demo-2.mp4">https://lucd.info/wp-content/uploads/2016/06/VMUGBe-24-Demo-2.mp4</a></video></div>
<h2>Development</h2>
<p>During the development of the vSphereDSC module, I will regularly need to test the code I have written. In the previous section I described how you &#8220;force&#8221; your Configuration to run immediately. In this section, I&#8217;m going to describe what needs to be done to get the vSphereDSC module, in the correct format, on the Pull Server.</p>
<h3>Scripted</h3>
<p>This is the least advanced way of getting the vSphereDSC module to the Pull Server. It&#8217;s all done through a script. The script is provided as file vSphereDSC-Module-To-Pull-Server.ps1 in the Tools folder.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$moduleName = 'vSphereDSC'
$sourceFolder = &quot;$($env:userprofile)\OneDrive\Github&quot;
$pullSrvName = 'pull.local.lab'

$srcPath = &quot;$($sourceFolder)\$($moduleName)&quot;
$pullSrv = &quot;\\$($pullSrvName)\DscService\Modules&quot;

$localPath = $env:PSModulePath.split(';') | where{$_ -like &quot;$($env:userprofile)*&quot;}

# Increment Version Build
$modVersion = Test-ModuleManifest -Path &quot;$($srcPath)\$($moduleName).psd1&quot; | Select -ExpandProperty Version
$newVersion = [Version]::new($modVersion.Major,$modVersion.Minor,$modVersion.Build + 1,$modVersion.Revision)
Update-ModuleManifest -Path &quot;$($srcPath)\$($moduleName).psd1&quot; -ModuleVersion $newVersion

# Copy new build to Pull server
$compressedModuleName = &quot;$($srcPath)\..\$($moduleName)_$($newVersion.Major).$($newVersion.Minor).$($newVersion.Build).$($newVersion.Revision).zip&quot;
Compress-Archive -Path &quot;$($srcPath)\*&quot; -DestinationPath $compressedModuleName
Copy-item -Path &quot;$($srcPath)\..\$($moduleName)_$($newVersion.ToString()).zip&quot; -Destination $pullSrv
New-DscChecksum -Path &quot;$($pullSrv)\$($moduleName)*.zip&quot;

# Copy new build to local Modules folder
if(Test-Path -Path &quot;$localPath\$moduleName&quot;)
{
    Get-ChildItem -Path &quot;$localPath\$moduleName&quot; -Recurse | Remove-Item -Recurse -Force -Confirm:$false -ErrorAction SilentlyContinue
    Remove-Item -Path &quot;$localPath\$moduleName&quot; -Recurse -Force -Confirm:$false -ErrorAction SilentlyContinue
}
Copy-Item -Path $srcPath -Destination $localPath -Recurse</pre><p></p>
<h4>Annotations</h4>
<p><strong>Line 1-3</strong>: Specify the name of the module, the location of the module and the name of the Pull Server.</p>
<p><strong>Line 5-6</strong>: Construct the source and destination paths</p>
<p><strong>Line 8</strong>: To have the latest version of the vSphereDSC module on my station, I will also copy the latest version here.</p>
<p><strong>Line 10-13</strong>: For each successive run of this script I increment the Build property of the Version by 1.</p>
<p><strong>Line 16-19</strong>: The module needs to be stored on the Pull Server, zipped and with the Version in the filename. And again we need to create a checksum for the module file.</p>
<p><strong>Line 22-27</strong>: Copy the new version locally</p>
<p>Once this is done, you start compiling and testing Configurations with the new version of the vSphereDSC module. See also the previous</p>
<h3>Build Server</h3>
<p>The automation of these steps will be automated. Documentation to follow !</p>
<p>&nbsp;</p>
<p>With this information I hope it will be easy to start using and contributing to the vSphereDSC module !</p>
<p>Enjoy !</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2016/06/07/vspheredsc-principles-operation/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		<enclosure url="https://lucd.info/wp-content/uploads/2016/06/VMUGBe-24-Demo-2.mp4" length="6791359" type="video/mp4" />

			</item>
		<item>
		<title>vSphereDSC &#8211; VmwFolder</title>
		<link>https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/</link>
					<comments>https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/#respond</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Sun, 05 Jun 2016 13:41:44 +0000</pubDate>
				<category><![CDATA[DSC]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VmwFolder]]></category>
		<category><![CDATA[vSphere]]></category>
		<category><![CDATA[vSphereDSC]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=5286</guid>

					<description><![CDATA[In this post I&#8217;ll introduce the first DSC resource from the vSphereDSC module, [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this post I&#8217;ll introduce the first DSC resource from the <strong>vSphereDSC</strong> module, the <strong>VmwFolder</strong> resource. Since this is the first post in the series, I will also expand a bit on how the vSphereDSC module is set up and which conventions I&#8217;m using.</p>
<p><a href="https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/vmwfolder/" rel="attachment wp-att-5311"><img decoding="async" class="alignnone size-full wp-image-5311" src="https://lucd.info/wp-content/uploads/2016/06/VmwFolder.jpg" alt="VmwFolder" width="427" height="275" srcset="https://www.lucd.info/wp-content/uploads/2016/06/VmwFolder.jpg 427w, https://www.lucd.info/wp-content/uploads/2016/06/VmwFolder-300x193.jpg 300w" sizes="(max-width: 427px) 100vw, 427px" /></a></p>
<p>A vSphere Folder is a resource which can exist rather independently in an existing vSphere environment. You can easily create some test Folders to get the hang and feel of the vSphereDSC module and play with DSC Configurations based on this vSphereDSC resource.</p>
<p><span id="more-5286"></span></p>
<h2>Lay of the Land</h2>
<p>In the <a href="https://www.lucd.info/2016/06/04/vspheredsc-intro/" target="_blank">Intro</a> of this series I already mentioned some of the issues I encountered, and how these had impact on the <strong>vSphereDSC</strong> module setup. It is my intention to gradually build up the <strong>vSphereDSC</strong> module, meaning that I will keep adding DSC Resources in future posts, but I will also be providing <strong>Unit and Integration tests</strong> (with <a href="https://github.com/pester/Pester" target="_blank">Pester</a>) and automate the module&#8217;s <strong>build process</strong> with <a href="https://www.appveyor.com/" target="_blank">Appveyor</a>.</p>
<p>The posts will be primarily based on a DSC <strong>Pull Server</strong> set up. This because that corresponds with what I use in my test environment, but also because I consider that architecture as the &#8220;<em>automated</em>&#8221; version of a DSC setup. That&#8217;s the one that you will be using in a real environment later on. This doesn&#8217;t mean that you can not test resources and Configurations without having to wait for the LCM interval to expire, as I will show later in this post.</p>
<p>The <strong>vSphereDSC</strong> module uses <strong>class-based</strong> DSC resources, that means you need to have <strong>WMF 5</strong> to use the module. All my tests have been done with the <a href="https://blogs.msdn.microsoft.com/powershell/2015/02/18/windows-management-framework-5-0-preview-february-2015-is-now-available/" target="_blank">WMF 5 February 2016 build</a> on the <strong>Pull</strong> and <strong>vEngine</strong> servers, so you will need to install that version as a minimum. On the Pull server and the vEngine server, which are Windows 2012 R2 servers, I have build 5.0.10586.117.</p>
<p><a href="https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/wmf5-w2k12r2/" rel="attachment wp-att-5288"><img loading="lazy" decoding="async" class="alignnone wp-image-5288 size-medium" src="https://lucd.info/wp-content/uploads/2016/06/wmf5-w2k12r2-300x109.jpg" alt="wmf5-w2k12r2" width="300" height="109" srcset="https://www.lucd.info/wp-content/uploads/2016/06/wmf5-w2k12r2-300x109.jpg 300w, https://www.lucd.info/wp-content/uploads/2016/06/wmf5-w2k12r2.jpg 419w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<p>On the Windows 10 station, that I use to write the Configuration files, I have 5.0.10586.122. Note that WMF 5 on Windows 10 is an official release, not a preview.</p>
<p><a href="https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/wmf5-w10/" rel="attachment wp-att-5289"><img loading="lazy" decoding="async" class="alignnone wp-image-5289 size-medium" src="https://lucd.info/wp-content/uploads/2016/06/wmf5-w10-300x113.jpg" alt="wmf5-w10" width="300" height="113" srcset="https://www.lucd.info/wp-content/uploads/2016/06/wmf5-w10-300x113.jpg 300w, https://www.lucd.info/wp-content/uploads/2016/06/wmf5-w10.jpg 394w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<p>As a side note, there is a <a href="https://social.technet.microsoft.com/wiki/contents/articles/33573.windows-powershell-build-numbers.aspx" target="_blank">Wiki page</a> (maintained by <a href="https://twitter.com/JanEgilRing" target="_blank">Jan Egil Ring</a>) that lists the PowerShell builds.</p>
<p>Until now I have been doing my development of the vSphereDSC module from a private BitBucket repository. But as of this post, the documented parts of the vSphereDSC module will be available on <a href="https://github.com/lucdekens/vSphereDSC" target="_blank">Github</a>, and from the <a href="https://www.powershellgallery.com/packages/vSphereDSC/" target="_blank">PSGallery</a>.</p>
<h2>The Layout</h2>
<p>As I already described in the Intro, the file structure of the <strong>vSphereDSC</strong> module is quite straightforward. Some design decisions were dictated by the issues that I encountered. The structure on Github now looks like this</p><pre class="urvanov-syntax-highlighter-plain-tag">$env: psmodulepath (folder)
&nbsp;&nbsp;&nbsp; |- vSphereDSC (folder)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- vSphereDSC.psm1 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- vSphereDSC.psd1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- vSphereDSCHelper.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- Tools (folder)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- Get-TargetGuid.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- Test-DscConfiguration.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- vEng-LCM-Configuration-Guid.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- vSphereDSC-Module-To-Pull-Server.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- Examples (folder)
            |- PowerCLI
                |- pcli01-PowerCLI.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- VmwFolder
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- cf01-vCenter-Folder.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- cf02-vCenter-Folder.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- cf03-vCenter-Folder.ps1

The actual code for the vSphereDSC module is located in the vSphereDSC.psm1 and vSphereDSCHelper.ps1 files.</pre><p>The reason why the Helper function are in a separate file and why this is not a nested module were already explained in the Intro. In short, we need to keep the PowerCLI cmdlets outside the class methods, and due to PowerCLI PSSnapin we can not use a module. As a bypass, the vSphereDSCHelper.ps1 file is dot-sourced in the vSphereDSC.psm1 file. This looks something like this</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">. &quot;$($PSScriptRoot)\vSphereDSCHelper.ps1&quot;</pre><p></p>
<h2>The Code</h2>
<p>If we look at the <strong>VmwFolder</strong> class, we can distinguish three distinct areas. Note that I use the Region directive to organise my code. This also allows me to show/hide the individual parts.</p>
<p><a href="https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/vmwfolder-1/" rel="attachment wp-att-5290"><img loading="lazy" decoding="async" class="alignnone wp-image-5290 size-medium" src="https://lucd.info/wp-content/uploads/2016/06/vmwFolder-1-300x271.jpg" alt="vmwFolder-1" width="300" height="271" srcset="https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-1-300x271.jpg 300w, https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-1.jpg 463w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<h3>Class Properties</h3>
<p>The <strong>Class Properties</strong> are just that, the properties that will be present in the <strong>VmwFolder</strong> class. But it is also the location where you specify the attributes of these properties. The most important one being the <strong>Key</strong> attribute. In fact all properties marked with the Key attribute will be taken together to form the &#8220;key&#8221; for a specific <strong>instance</strong> of the <strong>VmwFolder</strong> class. This &#8220;key&#8221; shall uniquely identify each instance of the VmwFolder class.</p>
<p><a href="https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/vmwfolder-2/" rel="attachment wp-att-5294"><img loading="lazy" decoding="async" class="alignnone wp-image-5294 size-thumbnail" src="https://lucd.info/wp-content/uploads/2016/06/vmwFolder-2-150x150.jpg" alt="vmwFolder-2" width="150" height="150" /></a></p>
<p>In the case of VmwFolder, the properties Path and Name are not sufficient to uniquely identify a VmwFolder instance. The reason is that we can have &#8220;Yellow&#8221; and &#8220;Blue&#8221; folders with the same name, who appear to be in the same location. The reason they appear to be in the same location is due to the hidden folders that exist in a vSphere environment.</p>
<p>Take for example the following situation where we seem to have a folder with the name <strong>Folder2</strong>, located under the Datacenter <strong>Homelab</strong>. From the Web Client we see the following. Is this one object or are these two different objects ?</p>
<p><a href="https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/vmwfolder-3b/" rel="attachment wp-att-5300"><img loading="lazy" decoding="async" class="alignnone wp-image-5300 size-medium" src="https://lucd.info/wp-content/uploads/2016/06/vmwFolder-3b-300x127.jpg" alt="vmwFolder-3b" width="300" height="127" srcset="https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-3b-300x127.jpg 300w, https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-3b.jpg 440w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<p>The old C# Client, where the &#8220;Yellow&#8221; and &#8220;Blue&#8221; foldernames originated, seems to say it are two different objects, provided we take the colour as a distinghuising characteristic.</p>
<p><a href="https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/vmwfolder-3c/" rel="attachment wp-att-5301"><img loading="lazy" decoding="async" class="alignnone wp-image-5301 size-medium" src="https://lucd.info/wp-content/uploads/2016/06/vmwFolder-3c-300x121.jpg" alt="vmwFolder-3c" width="300" height="121" srcset="https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-3c-300x121.jpg 300w, https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-3c.jpg 393w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<p>The answer, these are two different objects. And it is all due to the &#8220;<em>hidden</em>&#8221; folders that we could be confused. In a Datacenter object, there are pointers to the <strong>Hosts and Clusters</strong> view and the <strong>VM and Templates</strong> view. These pointers go to the hidden folders &#8220;<strong>host</strong>&#8221; and &#8220;<strong>vm</strong>&#8221; which are the respective parents for these two Folder objects that have the same name.</p>
<p><a href="https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/vmwfolder-3d/" rel="attachment wp-att-5302"><img loading="lazy" decoding="async" class="alignnone wp-image-5302 size-medium" src="https://lucd.info/wp-content/uploads/2016/06/vmwFolder-3d-300x127.jpg" alt="vmwFolder-3d" width="300" height="127" srcset="https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-3d-300x127.jpg 300w, https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-3d.jpg 440w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<p>And that is why the <strong>Type</strong> property is a <strong>Key</strong> property for the <strong>VmwFolder</strong> class.</p>
<h3>DSC Methods</h3>
<p>With this I mean the three methods that DSC requires to be present in each DSC class-based resource: <strong>Test</strong>, <strong>Set</strong> and <strong>Get</strong>.</p>
<p>As a general rule, I try to keep the code in these methods limited to the actual function of these three methods. For example, in the Test method, the code first checks of the folder exists (line 76), then depending on the desired state ($this.Ensure), the code returns $true or $false.</p>
<p><a href="https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/vmwfolder-5/" rel="attachment wp-att-5303"><img loading="lazy" decoding="async" class="alignnone wp-image-5303 size-medium" src="https://lucd.info/wp-content/uploads/2016/06/vmwFolder-5-300x91.jpg" alt="vmwFolder-5" width="300" height="91" srcset="https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-5-300x91.jpg 300w, https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-5-768x233.jpg 768w, https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-5.jpg 905w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<p>Note how on line 72, the vSphereDSCHelper.ps1 file is dot-sourced. This file contains all the code where we use PowerCLI cmdlets. In this particular case we needed to that, because in line 74 we call the Helper function <strong>Connect-VmwVIServer</strong>, which uses PowerCLI cmdlets.</p>
<h3>Class Helper Methods</h3>
<p>In this region we code all the methods that contain the more advanced code. While the Test, Set and Get methods were limited to their basic functionality logic, these Class Helper methods contain the &#8220;deeper&#8221; code. As an example, let&#8217;s have a look at the TestVmwFolder method.</p>
<p><a href="https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/vmwfolder-6/" rel="attachment wp-att-5304"><img loading="lazy" decoding="async" class="alignnone wp-image-5304 size-medium" src="https://lucd.info/wp-content/uploads/2016/06/vmwFolder-6-300x97.jpg" alt="vmwFolder-6" width="300" height="97" srcset="https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-6-300x97.jpg 300w, https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-6-768x248.jpg 768w, https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-6.jpg 878w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<p>In lines 106-111 we handle the logic that composes that path to the node, in this case a Folder, that we are looking for. This path is composed of the Path and the Name property. We need to code the special case where the node could be located in the RootFolder.</p>
<p>When the node is found, we need to check if the type corresponds with the Type of the Folder we are looking for (lines 114-115)</p>
<p>It&#8217;s this kind of logic that we want to keep out of the standard Test, Set and Get methods.</p>
<p>Note that there are quite a bit of Write-Verbose lines in the code. This use of the Write-Verbose cmdlet is indispensable when developing DSC resources in my opinion.</p>
<h3>External Helper Functions</h3>
<p>These are all the functions that use PowerCLI. As already explained, we can&#8217;t use PowerCLI inside the class methods. The solution I have chosen is to keep these functions outside of the class in a separate .ps1 file.</p>
<p>Most of the functions in there are rather straight-forward PowerCLI-based functions. Some of these were in fact already discussed in some other posts on this blog. See <a class="title" href="https://www.lucd.info/2016/05/05/universal-powercli-loader/" rel="bookmark">Universal PowerCLI Loader</a>, <a class="title" href="https://www.lucd.info/2016/06/03/get-inventoryplus-inventory-all-vsphere-objects/" rel="bookmark">Get-InventoryPlus – Inventory of all vSphere objects </a>and <a class="title" href="https://www.lucd.info/2016/06/03/vsphere-object-path/" rel="bookmark">vSphere Object by Path</a>.</p>
<p><a href="https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/vmwfolder-7/" rel="attachment wp-att-5305"><img loading="lazy" decoding="async" class="alignnone wp-image-5305 size-medium" src="https://lucd.info/wp-content/uploads/2016/06/vmwFolder-7-300x215.jpg" alt="vmwFolder-7" width="300" height="215" srcset="https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-7-300x215.jpg 300w, https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-7.jpg 355w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<h3>Verbosity</h3>
<p>Perhaps an interesting point to make in relation to the Write-Verbose I made earlier. We do want to see &#8220;verbose&#8221; output from the class methods and the Helper functions, but we don&#8217;t really want to see &#8220;verbose&#8221; output from all the PowerCLI cmdlets.</p>
<p>Instead of suppressing the verbosity on each individual cmdlet where we don&#8217;t want it, I opted for using the $PSDefaultParameterValues at the in the module.</p>
<p><a href="https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/vmwfolder-8/" rel="attachment wp-att-5306"><img loading="lazy" decoding="async" class="alignnone wp-image-5306 size-medium" src="https://lucd.info/wp-content/uploads/2016/06/vmwFolder-8-300x68.jpg" alt="vmwFolder-8" width="300" height="68" srcset="https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-8-300x68.jpg 300w, https://www.lucd.info/wp-content/uploads/2016/06/vmwFolder-8.jpg 351w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<p>That way I avoid the many lines that would scroll by during the loading of the PowerCLI modules and PSSnapin.</p>
<h2>Tools</h2>
<p>In the Tools folder I will include some scripts that I use during the development/test phase of the <strong>vSphereDSC</strong> module. The purpose and the proper use of these scripts will be explained in a separate post on the <strong>Principles of Operations</strong>.</p>
<h2>Examples</h2>
<h3>PowerCLI</h3>
<p>To start working with the vSphereDSC module we need to deploy <a href="https://communities.vmware.com/community/vmtn/automationtools/powercli/overview" target="_blank">PowerCLI</a> on the <strong>vEngine</strong> Server. And obviously we are going to do that with a DSC Configuration file. The sample file is named pcli01-PowerCLI.ps1.</p>
<p>The Configuration I provide to push PowerCLI to the vEngine server, is similar to what <a href="https://twitter.com/vinithmenon28" target="_blank">Vinith Menon</a> posted in his <a href="https://virtualize-automate.com/wp/index.php/2016/01/05/automate-powercli-install-across-your-windows-environment-using-powershell-dsc/" target="_blank">Automate PowerCLI Install across your Windows Environment using PowerShell DSC</a> post. Note that the Configuration file uses the <strong>Start-DscConfiguration</strong> cmdlet to immediately start the installation of PowerCLI on the vEngine server.</p>
<p>If all goes well you should see &#8220;PowerCLI installed&#8221; in the verbose output.</p>
<p><a href="https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/pcli/" rel="attachment wp-att-5307"><img loading="lazy" decoding="async" class="alignnone wp-image-5307 size-medium" src="https://lucd.info/wp-content/uploads/2016/06/pcli-300x80.jpg" alt="pcli" width="300" height="80" srcset="https://www.lucd.info/wp-content/uploads/2016/06/pcli-300x80.jpg 300w, https://www.lucd.info/wp-content/uploads/2016/06/pcli.jpg 639w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<h3>VmwFolder</h3>
<p>In the vSPhereDSC module a number of Configuration sample files are included.</p>
<p>Note that in this stage you will still need to provide the credentials of the vCenter account in clear text !</p>
<p>The samples are rather straight-forward. In the Principles of Operations I will show how you can organise smooth testing of your Configurations.</p>
<table>
<tbody>
<tr>
<td>Filename</td>
<td>Target</td>
<td>Description</td>
</tr>
<tr>
<td>cf01-vCenter-Folder.ps1</td>
<td>vCenter</td>
<td>Create a folder</td>
</tr>
<tr>
<td>cf02-vCenter-Folder.ps1</td>
<td>vCenter</td>
<td>Create two folders</td>
</tr>
<tr>
<td>cf03-vCenter-Folder.ps1</td>
<td>vCenter</td>
<td>Create two folders with the same name, but of different type</td>
</tr>
</tbody>
</table>
<p>This concludes the introduction of the <strong>VmwFolder</strong> resource.</p>
<p>&nbsp;</p>
<p>Since this is the first actual vSphereDSC resource that is made public, I would love to hear your feedback. Use the Issues option on the Github repository to report feedback, bug requests, feature request&#8230;</p>
<p>Enjoy!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2016/06/05/vspheredsc-vmwfolder/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>vSphereDSC &#8211; Intro</title>
		<link>https://www.lucd.info/2016/06/04/vspheredsc-intro/</link>
					<comments>https://www.lucd.info/2016/06/04/vspheredsc-intro/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Sat, 04 Jun 2016 20:07:13 +0000</pubDate>
				<category><![CDATA[DSC]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[vSphere]]></category>
		<category><![CDATA[vSphereDSC]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=5264</guid>

					<description><![CDATA[My attempts to marry DSC and vSphere have been going on for nearly [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>My attempts to marry <a href="https://msdn.microsoft.com/en-us/powershell/dsc/overview" target="_blank" rel="noopener noreferrer">DSC</a> and <a href="https://www.vmware.com/products/vsphere/" target="_blank" rel="noopener noreferrer">vSphere</a> have been going on for nearly a year* now. I showed some of my attempts and intermediate results at <a href="https://vmworld2015.lanyonevents.com/connect/speakerDetail.ww?PERSON_ID=F86B0BD6CB7516978E4E4E37C3E0D4CF" target="_blank" rel="noopener noreferrer">VMworld 2015</a>, in two sessions at the <a href="https://powershell.org/summit/" target="_blank" rel="noopener noreferrer">PowerShell + DevOps Global Summit</a> and recently during a session at the <a href="http://www.vmug.be/abstracts-24th-vmug-2nd-june-2016/" target="_blank" rel="noopener noreferrer">24th VMUGBE+</a>. But now I&#8217;m finally going public with the <strong>vSphereDSC</strong> module.</p>
<p>Since WMF 5 has been made available in preview, and still is in RTM at the moment I&#8217;m writing this, there have been constant changes to the way I was writing the DSC resources for vSphere. Since the <a href="https://blogs.msdn.microsoft.com/powershell/2015/02/18/windows-management-framework-5-0-preview-february-2015-is-now-available/" target="_blank" rel="noopener noreferrer">February 2016 WMF 5 release</a>, I now have a (somewhat) stable, working class-based solution. At least, that is what my initial tests seem to indicate.</p>
<p style="padding-left: 30px;"><a href="https://www.lucd.info/2016/06/04/vspheredsc-intro/vspheredsc-logo/" rel="attachment wp-att-5267"><img loading="lazy" decoding="async" class="alignnone wp-image-5267 size-full" src="https://lucd.info/wp-content/uploads/2016/06/vSphereDSC-Logo.jpg" alt="vSphereDSC-Logo" width="293" height="275" /></a></p>
<p>This intro for my <strong>vSphereDSC</strong> series, will lay out the playing field. I&#8217;ll explain the concept I&#8217;m using, show some of the issues I encountered and explain the layout of the <strong>vSphereDSC Resource module</strong>.</p>
<p>&nbsp;</p>
<p><sub>* &#8220;Wisely and slow; they stumble that run fast&#8221;, Romeo and Juliet, Act II, Scene III</sub></p>
<p><span id="more-5264"></span></p>
<h2>Intro</h2>
<p>To start you&#8217;ll need some knowledge on what <strong>DSC</strong> (Desired State Configuration) is all about of course. This series of posts is <strong>not</strong> going to do that!</p>
<p>But don&#8217;t despair, there are many free, online resources available that explain way better than I ever could, how <strong>DSC</strong> works. To name but a few:</p>
<ul>
<li>On MSDN <a href="https://msdn.microsoft.com/en-us/powershell/dsc/overview" target="_blank" rel="noopener noreferrer">Windows PowerShell Desired State Configuration Overview</a></li>
<li>On Simple Talk the 3-part series <a href="https://www.simple-talk.com/sysadmin/powershell/powershell-desired-state-configuration-the-basics/" target="_blank" rel="noopener noreferrer">PowerShell Desired State Configuration</a></li>
<li>The MVA Course <a href="https://mva.microsoft.com/en-US/training-courses/getting-started-with-powershell-desired-state-configuration-dsc--8672?l=ZwHuclG1_2504984382" target="_blank" rel="noopener noreferrer"><span title="Getting Started with PowerShell Desired State Configuration (DSC)">Getting Started with PowerShell Desired State Configuration (DSC)</span></a></li>
<li>On PowerShell.Org the <a href="https://www.penflip.com/powershellorg/the-dsc-book" target="_blank" rel="noopener noreferrer">The DSC Book </a></li>
<li>Many DSC articles in the <a href="https://www.powershellmagazine.com/" target="_blank" rel="noopener noreferrer">PowerShell Magazine</a> are definitely worth reading, as are all of their articles btw.</li>
</ul>
<p>Also check out the numerous blog posts and session recordings that have been made available. Google/Bing are your friends!</p>
<p>Not free, but there are also many DSC books available, and most of the major course vendors have one or more DSC Courses in their catalog nowadays.</p>
<p>I would also like to give a shout out to <a href="https://twitter.com/devblackops" target="_blank" rel="noopener noreferrer">Brandon Olin</a>, who is developing a DSC Resource module named <a href="https://github.com/devblackops/POSHOrigin_vSphere" target="_blank" rel="noopener noreferrer">POSHOrigin_vSphere</a>. He uses a different angle to configure a vSphere environment through DSC. At the moment he has an impressive VM resource in his module.</p>
<h2>The vEngine Concept</h2>
<p>The <strong>LCM</strong> (Local Configuration Manager) is the <strong>DSC</strong> component that takes care of the &#8220;<em>make it so</em>&#8221; part. On regular intervals, or when you tell it to, it compares the <strong>Configuration,</strong> it has or has received, with the actual situation on the host.</p>
<p>If there are differences, and if the LCM was configured to correct this, the LCM will &#8220;correct&#8221; the drift. It will &#8220;<strong><em>Make it so!</em></strong>&#8221;</p>
<p style="padding-left: 60px;"><a href="https://www.lucd.info/2016/06/04/vspheredsc-intro/dsc-intro-2/" rel="attachment wp-att-5274"><img loading="lazy" decoding="async" class="alignnone wp-image-5274 size-thumbnail" src="https://lucd.info/wp-content/uploads/2016/06/dsc-intro-2-150x150.jpg" alt="dsc-intro-2" width="150" height="150" srcset="https://www.lucd.info/wp-content/uploads/2016/06/dsc-intro-2-150x150.jpg 150w, https://www.lucd.info/wp-content/uploads/2016/06/dsc-intro-2.jpg 236w" sizes="auto, (max-width: 150px) 100vw, 150px" /></a></p>
<p>The first decision I had to make, was where are we going to run this LCM that will interact with a vSphere environment. An obvious choice would be to install it on the vCenter server, but there are some strong counter arguments for that.</p>
<ul>
<li>The vCenter Server, with the introduction of the VCSA (vCenter Appliance), is not necessarily running a Windows OS</li>
<li>The vSphereDSC resource module should be able to configure <strong>any</strong> vSphere Server, that includes a stand-alone ESXi host</li>
<li>For support and performance reasons we would probably not want to install additional &#8220;features&#8221; on a vSphere Server</li>
<li>Changes to a vSphere Server (upgrades, migrations&#8230;) should not impact the vSphere DSC configuration and resources</li>
</ul>
<p>The obvious choice, for me, was to introduce a &#8220;helper&#8221; server, the <strong>vEngine</strong>!</p>
<p>The LCM that configures/corrects the vSphere environment, will run on this <strong>vEngine Server</strong>. The vEngine Server only needs PowerShell and the PowerCLI modules/pssnapins. And it will &#8220;talk&#8221; with the vSphere Server via PowerCLI.</p>
<p style="padding-left: 30px;"><a href="https://www.lucd.info/2016/06/04/vspheredsc-intro/veng-architecture-2/" rel="attachment wp-att-5279"><img loading="lazy" decoding="async" class="alignnone wp-image-5279 size-medium" src="https://lucd.info/wp-content/uploads/2016/06/vEng-Architecture-2-300x223.png" alt="vEng-Architecture-2" width="300" height="223" srcset="https://www.lucd.info/wp-content/uploads/2016/06/vEng-Architecture-2-300x223.png 300w, https://www.lucd.info/wp-content/uploads/2016/06/vEng-Architecture-2.png 520w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<p>The workflow for this setup will look something like this</p>
<p style="padding-left: 30px;"><a href="https://www.lucd.info/2016/06/04/vspheredsc-intro/veng-architecture-3/" rel="attachment wp-att-5280"><img loading="lazy" decoding="async" class="alignnone wp-image-5280 size-medium" src="https://lucd.info/wp-content/uploads/2016/06/vEng-Architecture-3-300x208.png" alt="vEng-Architecture-3" width="300" height="208" srcset="https://www.lucd.info/wp-content/uploads/2016/06/vEng-Architecture-3-300x208.png 300w, https://www.lucd.info/wp-content/uploads/2016/06/vEng-Architecture-3-768x531.png 768w, https://www.lucd.info/wp-content/uploads/2016/06/vEng-Architecture-3.png 776w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<p>(1) The vSphere administrator makes sure he has the required DSC Resource modules on his workstation. This includes the vSphereDSC module. These modules can be retrieved from public or private repositories.</p>
<p>(2) The vSphere administrator creates a Configuration for his vSphere environment.</p>
<p>(3) The Configuration is pushed to the DSC Pull Server. The Configuration is stored there as a MOF file.</p>
<p>(4) The LCM on the vEngine will query the Pull Server at regular intervals to check if there is a new Configuration present. If there is, it will check if all the required resources for the new Configuration are present. If not, it will pull these DSC Resources from the Pull Server.</p>
<p>If there is no new Configuration, the LCM will use it&#8217;s local Current Configuration to &#8220;test&#8221; against the vSphere environment. If there is a drift, and if the LCM is configured to correct this, it will apply the Configuration on the vSphere environment.</p>
<h2>Issues</h2>
<p>During my work the vSphereDSC module I did encounter several &#8220;issues&#8221;. Some where caused by actual bugs that hopefully will be fixed when WMF 5 is released. Others were/are in fact caused by some of the design decisions in WMF 5. Remember that WMF 5 as we can currently use, is not yet the official release version.</p>
<p>A short summary of the issues (and the effect they had on the vSphereDSC module):</p>
<ul>
<li>The original idea to use Disconnected Sessions suffered from occasional crashes in the WMI that is running the LCM. After talking with the PowerShell Team this appears to be a know issue, but the fix is not yet present in the public WMF 5 build. So Disconnected Sessions are &#8220;On hold&#8221; for now.</li>
<li>Class-based DSC resources, at the moment, do <strong>not</strong> support <strong>multiple files</strong>. That means all the vSphereDSC resources will be in one file. And that one file is configured in the RootModule parameter in the Manifest. Besides a less cleaner organisation, this didn&#8217;t have a big impact.</li>
<li>The LCM <strong>resets the runspace</strong> each time a class method is invoked. As a consequence, there is no passing of information between successive invocations of class methods. This also caused issues with the PowerCLI Modules and PSSnapins. To fix this I moved all PowerCLI lines to a &#8220;helper&#8221; file outside the class methods. This way the number of  times we need to load the PowerCLI Modules and PSSnapins is also limited, and it improves the runtime of the class methods.</li>
<li>A PSSnapin that is loaded inside a module is only visible <strong>inside that module</strong>. This caused some problems when I was still struggling with the previous issue. For now, the external, PowerCLI Helper functions are in one .ps1 file  that is dot-sourced from within the class methods. I will need to revisit this, and check if I can package the Helper functions in a module.</li>
<li>Class-based DSC Resources do not support inheritance. I was hoping to use the same object hierarchy that is present in vSphere (for example ExtensibleManagedObject &#8211; ManagedEntity &#8211; VirtualMachine), but that had to be abandoned.</li>
</ul>
<h2>Module Layout</h2>
<p>As you have gathered from the Issues paragraph, there have been some changes to my original plan. A quick summary of what I have and how I organised it.</p>
<p>In fact I try to follow the layout as described <a href="https://github.com/PowerShell/DscResources" target="_blank" rel="noopener noreferrer">PowerShell\DSCResources</a> as close as possible. The following is a quick treeview of part of my private repository. It shows the general layout, more details will follow in the posts that will discuss individual resources.</p><pre class="urvanov-syntax-highlighter-plain-tag">$env: psmodulepath (folder)
&nbsp;&nbsp;&nbsp; |- vSphereDSC (folder)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- vSphereDSC.psm1 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- vSphereDSC.psd1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- vSphereDSCHelper.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- Tests (folder)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- Integration (folder)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- Unit (folder)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- Tools (folder)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- Get-TargetGuid.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- Test-DscConfiguration.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- vEng-LCM-Configuration-Guid.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- vSphereDSC-Module-To-Pull-Server.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- Examples (folder)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- vmwFolder
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- cf01-vCenter-Folder.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- cf02-vCenter-Folder.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- vmwDatacenter
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- cd01-vCenter-Datacenter.ps1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- vmwVMHost
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |- vmwCluster</pre><p></p>
<h2>Use Cases</h2>
<p>A question I regularly get when presenting the vSphereDSC module, is why would you use DSC to configure your vSphere environment ? They are already automating their vSphere environment through PowerCLI, why would they need to change that ?</p>
<p>I used to sometimes reply with &#8220;Why do people climb mountains ?&#8221;. But that was of course intended as an icebreaker. There are, in my opinion, enough reason to switch to configuring your vSphere environment through DSC.</p>
<p>Because I know each one of you will encounter the same question(s) when you propose DSC to configure your vSphere environment, I decided to start listing the arguments and some potential use cases in here. And my list is obviously far from complete, please contribute, and send me arguments and use cases you see.</p>
<ul>
<li>&#8220;Pets vs cattle&#8221;. Independent who coined the analogy first, this concept should be one of the major arguments you use in a DSC vSphere discussion. <strong>Scale out</strong> instead of scale up!</li>
<li>&#8220;Scale * Complexity -gt Skill&#8221;. This comes from a TechEd 2013 presentation (<a href="https://video.ch9.ms/sessions/teched/na/2013/MDC-B302.pptx" target="_blank" rel="noopener noreferrer">MDC-B302</a>) by  <a href="https://twitter.com/jsnover" target="_blank" rel="noopener noreferrer">Jeffrey Snover</a> and <a href="https://twitter.com/KhansenHansen" target="_blank" rel="noopener noreferrer">Kenneth Hansen</a>. <strong>Declarative</strong>, <strong>autonomous</strong> and <strong>idempotent</strong> deployment, configuration and conformance of standards-based managed elements.</li>
<li>&#8220;Change is the primary cause of outage&#8221;. Comes from the same TechEd presentation as the previous bullet. <strong>Automation</strong>, in this case through DSC, will allow a continuous service availability, a continuous release cycle and continuous deployment.</li>
<li>Separation of <a href="https://msdn.microsoft.com/en-us/powershell/dsc/configdata" target="_blank" rel="noopener noreferrer">Configuration and Environment</a> data. You would only need to source control your master Configuration logic, and the Environment data individually.</li>
</ul>
<p>&nbsp;</p>
<p>This concludes the vSphereDSC Intro. The scene has been set<br />
What&#8217;s next ?</p>
<p>In the next posts in this series, I will start expanding into the individual resources that are present in the <strong>vSphereDSC</strong> module.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2016/06/04/vspheredsc-intro/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
