PowerShell DSC Journey – Day 16

When I left off yesterday I had a somewhat functioning Set-TargetResource function. I use functioning in the way that when something kind of works and doesn’t throw errors but doesn’t actually do anything functions. So, today I am going to be figuring out where I screwed up my logic and getting this Resource to work. And hopefully this doesn’t turn into a smaller version of War and Peace.

Here is my Set-TargetResource in it’s entirety.

#region
function Set-TargetResource
{
	[CmdletBinding()]
	param
	(
		[System.Boolean]
		$DVDDrive,

		[System.String]
		$VMNetwork,

		[System.UInt64]
		$CPUCount,

		[ValidateSet("Present","Absent")]
		[System.String]
		$Ensure,

		[parameter(Mandatory = $true)]
		[System.String]
		$Name,

		[parameter(Mandatory = $true)]
		[System.String]
		$VMMServer
	)

	#Write-Verbose "Use this cmdlet to deliver information about command processing."

	#Write-Debug "Use this cmdlet to write debug information while troubleshooting."

	#Include this line if the resource requires a system reboot.
	#$global:DSCMachineStatus = 1

    Write-Verbose "VMMServer is $VMMServer"
    Write-Verbose "Hardware Profile Name is $Name"

    #Check if VirtualMachineManager module is present for SCVMM cmdlets
        If(!(Get-Module -ListAvailable -Name VirtualMachineManager))
        {
            Throw "The VirtualMachineManager Module was not found.  Please ensure this module is available by installing the VMM Console.  For information
            On installing the VMM Console see:  http://technet.microsoft.com/en-us/library/gg610627.aspx"
        }

    #Check to see if Hardware Profile exists
        Write-Verbose "Checking if the Hardware Profile $Name exists"
        $HWProfile = Get-SCHardwareProfile -VMMServer $VMMServer

        If($HWProfile.Name -match $Name)
        {
            Write-Verbose "The Hardware Profile was found"
            $ResourceHWProfile = Get-SCHardwareProfile -VMMServer $VMMServer | Where-Object Name -eq $Name
            $HWProfileID = $ResourceHWProfile.ID

            #If Hardware Profile Should not exist, remove it
            If($Ensure = "Absent")
            {
                Write-Verbose "Hardware Profile $Name Should be $Ensure"
                Get-SCHardwareProfile -VMMServer $VMMServer -ID $HWProfileID | Remove-SCHardwareProfile
                Write-Verbose "Hardware Profile $Name is $Ensure"
            }
            Else
            {
                #Hardware Profile should be present with the correct settings.  Check the settings.
                    If($DVDDrive -eq $HWProfile.VirtualDVDDrives.Enabled)
                    {
                        Write-Verbose "DVDDrive is already set properly"
                    }
                    Else
                    {
                        If($DVDDrive -eq $True)
                        {
                            New-SCVirtualDVDDrive -HardwareProfile $Name -LUN 1 -Bus 0
                            Write-Verbose "DVDDrive has been created"
                        }
                        Else
                        {
                            Get-SCVirtualDVDDrive -HardwareProfile $Name | Remove-SCVirtualDVDDrive
                            Write-Verbose "DVDDrive has been removed"
                        }
                    }

                    If($CPUCount -ne $HWProfile.CPUCount)
                    {
                        Write-Verbose "CPUCount is $HWProfile.CPUCount, should be $CPUCount"
                        Set-SCHardwareProfile -HardwareProfile $Name -CPUCount $CPUCount
                        Write-Verbose "CPUCount Set to $CPUCount"                                        
                    }
                    Else
                    {
                        Write-Verbose "CPUCount is already set to $CPUCount"
                    }
                    If($VMNetwork -ne $HWProfile.VirtualNetworkAdapters.VMNetwork)
                    {
                        Write-Verbose "VMNetwork set to $HWProfile.VirtualNetworkAdapters.VMNetwork, should be $VMNetwork"
                        Get-SCVirtualNetworkAdapter -VMMServer $VMMSErver -HardwareProfile $Name | Set-SCVirtualNetworkAdapter -VirtualNetwork $VMNetwork
                        Write-Verbose "VMNetwork set to $VMNetwork"
                    }
                    Else
                    {
                        Write-Verbose "VMNetwork is already set to $VMNetwork"
                    }
                        
                }
                           
            }
        Else
        {
            Write-Verbose "The Hardware Profile was not found.  Creating new Hardware Profile $Name"

            New-SCHardwareProfile -VMMServer $VMMSErver -Name $Name

            If($DVDDrive -eq $True)
            {
                New-SCVirtualDVDDrive -HardwareProfile $Name -LUN 1 -Bus 0
                Write-Verbose "DVDDrive has been created"
            }
            Else
            {
                Write-Verbose "DVDDrive is set to $False, no DVDDrive created"
            }

            If($CPUCount -gt 0)
            {
                Write-Verbose "Setting CPUCount to $CPUCount"
                Set-SCHardwareProfile -HardwareProfile $Name -CPUCount $CPUCount
                Write-Verbose "CPUCount Set to $CPUCount" 
            }
            Else
            {
                Write-Verbose "CPU Count set to 0 or not specified, CPU Count should be at least 1"
            }

            If($VMNetwork -ne $null)
            {
                Write-Verbose "Setting VMNetwork to $VMNetwork"
                Get-SCVirtualNetworkAdapter -VMMServer $VMMSErver -HardwareProfile $Name | Set-SCVirtualNetworkAdapter -VirtualNetwork $VMNetwork
                Write-Verbose "VMNetwork set to $VMNetwork"
            }
            Else
            {
                Write-Verbose "VMNetwork not specified"
            }
        }
}
#endregion

The first problem I noticed is that when I run this test of my Set-TargetResource (in which I am testing for a Hardware Profile that doesn’t exist), here is the output I get.

PS C:\Scripts> Set-TargetResource -Name "DSCWEB Hardware Profile" -VMMServer MY-VMM-SERVER1 -Ensure Present -Verbose
VERBOSE: VMMServer is MY-VMM-SERVER1
VERBOSE: Hardware Profile Name is DSCWEB Hardware Profile
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine Manager\bin\virtualmachinemanager.R2Aliases.ps1'.
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine Manager\bin\VirtualMachineManagerLibraryClientCleanup.ps1'.
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine Manager\bin\psModules\virtualmachinemanager\..\..\virtualmachinemanager.R2AdvFunc.psm1'.
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine Manager\bin\psModules\virtualmachinemanager\..\..\Microsoft.SystemCenter.VirtualMachineManager.dll'.
VERBOSE: Checking if the Hardware Profile DSCWEB Hardware Profile exists
VERBOSE: The Hardware Profile was not found.  Creating new Hardware Profile DSCWEB Hardware Profile


CPUCount                            : 1
Memory                              : 512
DynamicMemoryEnabled                : False
DynamicMemoryMaximumMB              : 
DynamicMemoryBufferPercentage       : 
MemoryWeight                        : 
VirtualVideoAdapterEnabled          : False
MonitorMaximumCount                 : 
MonitorResolutionMaximum            : 
BootOrder                           : 
FirstBootDevice                     : 
SecureBootEnabled                   : 
UndoDisksEnabled                    : False
CPUType                             : 3.60 GHz Xeon (2 MB L2 cache)
IsHighlyAvailable                   : False
HAVMPriority                        : 
IsDRProtectionRequired              : False
RecoveryPointObjective              : 
LimitCPUFunctionality               : False
LimitCPUForMigration                : False
ExpectedCPUUtilization              : 20
DiskIO                              : 0
NetworkUtilization                  : 0
RelativeWeight                      : 100
CPUReserve                          : 0
CPUMax                              : 100
CPUPerVirtualNumaNodeMaximum        : 
MemoryPerVirtualNumaNodeMaximumMB   : 
VirtualNumaNodesPerSocketMaximum    : 
DynamicMemoryMinimumMB              : 
NumLockEnabled                      : 
NumaIsolationRequired               : 
Generation                          : 1
VirtualDVDDrives                    : {}
ShareSCSIBus                        : False
VirtualNetworkAdapters              : {}
VirtualFibreChannelAdapters         : {}
VirtualFloppyDrive                  : DSCWEB Hardware Profile
VirtualCOMPorts                     : {COM1, COM2}
VirtualSCSIAdapters                 : {}
CapabilityProfile                   : 
CapabilityProfileCompatibilityState : Compatible
GrantedToList                       : {}
UserRoleID                          : 75700cd5-893e-4f68-ada7-50ef4668acc6
UserRole                            : Administrator
Owner                               : jacob.benson
ObjectType                          : HardwareProfile
Accessibility                       : Public
Name                                : DSCWEB Hardware Profile
IsViewOnly                          : False
Description                         : 
AddedTime                           : 6/16/2014 7:21:42 AM
ModifiedTime                        : 6/16/2014 7:21:42 AM
Enabled                             : True
MostRecentTask                      : Create hardware profile
ServerConnection                    : Microsoft.SystemCenter.VirtualMachineManager.Remoting.ServerConnection
ID                                  : 083da7f1-54af-4720-b4a4-dad908b76dfa
MarkedForDeletion                   : False
IsFullyCached                       : True
MostRecentTaskIfLocal               : Create hardware profile

VERBOSE: DVDDrive is set to False, no DVDDrive created
VERBOSE: CPU Count set to 0 or not specified, CPU Count should be at least 1
VERBOSE: Setting VMNetwork to 
Set-SCVirtualNetworkAdapter : Cannot validate argument on parameter 'VirtualNetwork'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:138 char:136
+ ... rofile $Name | Set-SCVirtualNetworkAdapter -VirtualNetwork $VMNetwork
+                                                                ~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Set-SCVirtualNetworkAdapter], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.SystemCenter.VirtualMachineManager.Cmdlets.SetNICCmdlet
 
VERBOSE: VMNetwork set to

Couple of things to note here. It didn’t find the Hardware Profile, so it created it. However, I didn’t specify anything for the DVD Drive, but the verbose output indicates that it was set to False, so it did not create a DVD Drive, so that needs to be fixed. The second issue is that the verbose output indicates that the CPU count set to 0 or not specified, CPU count should be at least 1. If I don’t specify a CPU count the Hardware Profile creation defaults to 1 CPU, so the message should indicate that. And lastly it just errored out on setting the VMNetwork because I didn’t specify one.

First things first, here is the section of code I have to handle the DVD Drive.

If($DVDDrive -eq $True)
            {
                New-SCVirtualDVDDrive -HardwareProfile $Name -LUN 1 -Bus 0
                Write-Verbose "DVDDrive has been created"
            }
            Else
            {
                Write-Verbose "DVDDrive is set to $False, no DVDDrive created"
            }

While thinking about this, it occurs to me that maybe I should set this to default to True, because I imagine that in almost every case you are going to want a DVD Drive on your server. I feel like that is a better solution than adding in another ElseIf section that has the Null case. Do people agree? I changed the parameter in the Set-TargetResource Function so that $DVDDrive = $True, and that means the existing code block should work fine.

Second minor issue is changing the Verbose text when the CPU Count is set to 0 or not specified. This particular section of code I changed from:

           If($CPUCount -gt 0)
            {
                Write-Verbose "Setting CPUCount to $CPUCount"
                Set-SCHardwareProfile -HardwareProfile $Name -CPUCount $CPUCount
                Write-Verbose "CPUCount Set to $CPUCount" 
            }
            Else
            {
                Write-Verbose "CPU Count set to 0 or not specified, CPU Count set to 1"
            }

To:

 If($CPUCount -gt 0)
            {
                Write-Verbose "Setting CPUCount to $CPUCount"
                Set-SCHardwareProfile -HardwareProfile $Name -CPUCount $CPUCount
                Write-Verbose "CPUCount Set to $CPUCount" 
            }
            Else
            {
                Write-Verbose "CPUCount set to 0 or not specified, setting CPUCount to 1"
                Set-SCHardwareProfile -HardwareProfile $Name -CPUCount 1
                Write-Verbose "CPUCount set to 1"
            }

Of course after doing this I think, should I just set the CPUCount parameter to default to 1? I mean, you need a CPU for it to run, and it defaults to 1 anyways without even setting anything. I realize the code in the Else block is a little redundant, but for consistency sake I left it that way so somebody reading it wouldn’t be like “why did he set the hardware profile in the first section and not the second?”. I could also make CPUCount a mandatory parameter, but that seems a little excessive when it just defaults to 1 anyways. Hmm. I don’t think there is a good answer to this. I am going to set CPUCount to default to 1 and just change the Else statement to use -CPUCount $CPUCount for now. I don’t like the idea of hard coding parameter values into a DSC Configuration, but in this particular case I think it is justifiable.

Alright, now for the last problem with the VMNetwork. If I don’t specify it, it shouldn’t just freak out and throw and error, it needs to say something useful. Here is my current code.

            If($VMNetwork -ne $null)
            {
                Write-Verbose "Setting VMNetwork to $VMNetwork"
                Get-SCVirtualNetworkAdapter -VMMServer $VMMSErver -HardwareProfile $Name | Set-SCVirtualNetworkAdapter -VirtualNetwork $VMNetwork
                Write-Verbose "VMNetwork set to $VMNetwork"
            }
            Else
            {
                Write-Verbose "VMNetwork not specified"
            }

The problem here is that I thought that checking to see if the parameter was not equal to Null mean it would also check to make sure it wasn’t empty. Clearly this is not the case. So how do I check for both cases? It appears based on some Google searches the best way to do this is to change it from If($VMNetwork -ne $null) to just If($VMNetwork) which checks for Null or Empty.

With those changes done, lets test again and see what happens (I deleted the Hardware Configuration created from the previous test).

Much better!

PS C:\Scripts> Set-TargetResource -Name "DSCWEB Hardware Profile" -VMMServer MY-VMM-SERVER1 -Ensure Present -Verbose
VERBOSE: VMMServer is MY-VMM-SERVER1
VERBOSE: Hardware Profile Name is DSCWEB Hardware Profile
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine 
Manager\bin\virtualmachinemanager.R2Aliases.ps1'.
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine 
Manager\bin\VirtualMachineManagerLibraryClientCleanup.ps1'.
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine 
Manager\bin\psModules\virtualmachinemanager\..\..\virtualmachinemanager.R2AdvFunc.psm1'.
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine 
Manager\bin\psModules\virtualmachinemanager\..\..\Microsoft.SystemCenter.VirtualMachineManager.dll'.
VERBOSE: Checking if the Hardware Profile DSCWEB Hardware Profile exists
VERBOSE: The Hardware Profile was not found.  Creating new Hardware Profile DSCWEB Hardware Profile


CPUCount                            : 1
Memory                              : 512
DynamicMemoryEnabled                : False
DynamicMemoryMaximumMB              : 
DynamicMemoryBufferPercentage       : 
MemoryWeight                        : 
VirtualVideoAdapterEnabled          : False
MonitorMaximumCount                 : 
MonitorResolutionMaximum            : 
BootOrder                           : 
FirstBootDevice                     : 
SecureBootEnabled                   : 
UndoDisksEnabled                    : False
CPUType                             : 3.60 GHz Xeon (2 MB L2 cache)
IsHighlyAvailable                   : False
HAVMPriority                        : 
IsDRProtectionRequired              : False
RecoveryPointObjective              : 
LimitCPUFunctionality               : False
LimitCPUForMigration                : False
ExpectedCPUUtilization              : 20
DiskIO                              : 0
NetworkUtilization                  : 0
RelativeWeight                      : 100
CPUReserve                          : 0
CPUMax                              : 100
CPUPerVirtualNumaNodeMaximum        : 
MemoryPerVirtualNumaNodeMaximumMB   : 
VirtualNumaNodesPerSocketMaximum    : 
DynamicMemoryMinimumMB              : 
NumLockEnabled                      : 
NumaIsolationRequired               : 
Generation                          : 1
VirtualDVDDrives                    : {}
ShareSCSIBus                        : False
VirtualNetworkAdapters              : {}
VirtualFibreChannelAdapters         : {}
VirtualFloppyDrive                  : DSCWEB Hardware Profile
VirtualCOMPorts                     : {COM1, COM2}
VirtualSCSIAdapters                 : {}
CapabilityProfile                   : 
CapabilityProfileCompatibilityState : Compatible
GrantedToList                       : {}
UserRoleID                          : 75700cd5-893e-4f68-ada7-50ef4668acc6
UserRole                            : Administrator
Owner                               : jacob.benson
ObjectType                          : HardwareProfile
Accessibility                       : Public
Name                                : DSCWEB Hardware Profile
IsViewOnly                          : False
Description                         : 
AddedTime                           : 6/16/2014 7:56:15 AM
ModifiedTime                        : 6/16/2014 7:56:15 AM
Enabled                             : True
MostRecentTask                      : Create hardware profile
ServerConnection                    : Microsoft.SystemCenter.VirtualMachineManager.Remoting.ServerC
                                      onnection
ID                                  : fdcaad29-7709-4ead-ad79-9264ae2e5820
MarkedForDeletion                   : False
IsFullyCached                       : True
MostRecentTaskIfLocal               : Create hardware profile

Connection            : None
ISOId                 : 
ISO                   : 
HostDrive             : 
BusType               : 
Bus                   : 
Lun                   : 
ISOLinked             : False
ObjectType            : VirtualDVDDrive
Accessibility         : Public
Name                  : DSCWEB Hardware Profile
IsViewOnly            : False
Description           : 
AddedTime             : 6/16/2014 7:56:15 AM
ModifiedTime          : 6/16/2014 7:56:15 AM
Enabled               : True
MostRecentTask        : Create virtual DVD drive
ServerConnection      : Microsoft.SystemCenter.VirtualMachineManager.Remoting.ServerConnection
ID                    : e6520ca7-0348-45cc-8e51-758e9ccc462c
MarkedForDeletion     : False
IsFullyCached         : True
MostRecentTaskIfLocal : Create virtual DVD drive

VERBOSE: DVDDrive has been created
VERBOSE: Setting CPUCount to 1
CPUCount                            : 1
Memory                              : 512
DynamicMemoryEnabled                : False
DynamicMemoryMaximumMB              : 
DynamicMemoryBufferPercentage       : 
MemoryWeight                        : 
VirtualVideoAdapterEnabled          : False
MonitorMaximumCount                 : 
MonitorResolutionMaximum            : 
BootOrder                           : 
FirstBootDevice                     : 
SecureBootEnabled                   : 
UndoDisksEnabled                    : False
CPUType                             : 3.60 GHz Xeon (2 MB L2 cache)
IsHighlyAvailable                   : False
HAVMPriority                        : 
IsDRProtectionRequired              : False
RecoveryPointObjective              : 
LimitCPUFunctionality               : False
LimitCPUForMigration                : False
ExpectedCPUUtilization              : 20
DiskIO                              : 0
NetworkUtilization                  : 0
RelativeWeight                      : 100
CPUReserve                          : 0
CPUMax                              : 100
CPUPerVirtualNumaNodeMaximum        : 
MemoryPerVirtualNumaNodeMaximumMB   : 
VirtualNumaNodesPerSocketMaximum    : 
DynamicMemoryMinimumMB              : 
NumLockEnabled                      : 
NumaIsolationRequired               : 
Generation                          : 1
VirtualDVDDrives                    : {DSCWEB Hardware Profile}
ShareSCSIBus                        : False
VirtualNetworkAdapters              : {}
VirtualFibreChannelAdapters         : {}
VirtualFloppyDrive                  : DSCWEB Hardware Profile
VirtualCOMPorts                     : {COM1, COM2}
VirtualSCSIAdapters                 : {}
CapabilityProfile                   : 
CapabilityProfileCompatibilityState : Compatible
GrantedToList                       : {}
UserRoleID                          : 75700cd5-893e-4f68-ada7-50ef4668acc6
UserRole                            : Administrator
Owner                               : jacob.benson
ObjectType                          : HardwareProfile
Accessibility                       : Public
Name                                : DSCWEB Hardware Profile
IsViewOnly                          : False
Description                         : 
AddedTime                           : 6/16/2014 7:56:15 AM
ModifiedTime                        : 6/16/2014 7:56:16 AM
Enabled                             : True
MostRecentTask                      : Change properties of hardware profile
ServerConnection                    : Microsoft.SystemCenter.VirtualMachineManager.Remoting.ServerC
                                      onnection
ID                                  : fdcaad29-7709-4ead-ad79-9264ae2e5820
MarkedForDeletion                   : False
IsFullyCached                       : True
MostRecentTaskIfLocal               : Change properties of hardware profile

VERBOSE: CPUCount Set to 1
VERBOSE: VMNetwork not specified, no VMNetwork was set

The one thing I don’t like about this, is that it still sets it set the CPUCount, when in all actuality it was already set by default. So, I am going to change that section again to this.

            Else
            {
                Write-Verbose "CPUCount set to 0 or not specified, CPUCount set to 1 by default"
            }

I verified that the Hardware Profile has 1 CPU, the DVD Drive is Enabled, and the Virtual Network is not set. Not setting a VMNetwork appears to mean that no settings in VirtualNetworkAdapters are set, which is good to know.

Ok, with that all done, I run it again because I remember there was a problem with this. Here are the important parts from this test.

PS C:\Scripts> Set-TargetResource -Name "DSCWEB Hardware Profile" -VMMServer MY-VMM-SERVER1 -Ensure Present -Verbose
VERBOSE: VMMServer is MY-VMM-SERVER1
VERBOSE: Hardware Profile Name is DSCWEB Hardware Profile
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine Manager\bin\virtualmachinemanager.R2Aliases.ps1'.
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine Manager\bin\VirtualMachineManagerLibraryClientCleanup.ps1'.
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine Manager\bin\psModules\virtualmachinemanager\..\..\virtualmachinemanager.R2AdvFunc.psm1'.
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine Manager\bin\psModules\virtualmachinemanager\..\..\Microsoft.SystemCenter.VirtualMachineManager.dll'.
VERBOSE: Checking if the Hardware Profile DSCWEB Hardware Profile exists
VERBOSE: The Hardware Profile was found
VERBOSE: Hardware Profile DSCWEB Hardware Profile Should be Absent
*DISPLAYS HARDWARE PROFILE INFORMATION*
VERBOSE: Hardware Profile DSCWEB Hardware Profile is Absent

Uh. What. That looks to be a massive fail on my part. Although, I don’t understand what the problem is here. It checks if it exists, it finds that it exists, and then it is going through the block where $Ensure = Absent, even though I have $Ensure = Present. Of course, then it is removing the profile as well, which is fun. I add this line to my code right above the line for If($Ensure = Absent), Write-Verbose “Ensure set to $Ensure”.

And I get this, which is even more puzzling.

PS C:\Scripts> Set-TargetResource -Name "DSCWEB Hardware Profile" -VMMServer MY-VMM-SERVER1 -Ensure Present -Verbose
VERBOSE: VMMServer is MY-VMM-SERVER1
VERBOSE: Hardware Profile Name is DSCWEB Hardware Profile
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine Manager\bin\virtualmachinemanager.R2Aliases.ps1'.
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine Manager\bin\VirtualMachineManagerLibraryClientCleanup.ps1'.
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine Manager\bin\psModules\virtualmachinemanager\..\..\virtualmachinemanager.R2AdvFunc.psm1'.
VERBOSE: Loading module from path 'C:\Program Files\Microsoft System Center 2012 R2\Virtual Machine Manager\bin\psModules\virtualmachinemanager\..\..\Microsoft.SystemCenter.VirtualMachineManager.dll'.
VERBOSE: Checking if the Hardware Profile DSCWEB Hardware Profile exists
VERBOSE: The Hardware Profile was found
VERBOSE: Ensure set to Present
VERBOSE: Hardware Profile DSCWEB Hardware Profile Should be Absent

It says that $Ensure = Present, so why the hell is it going through that block of code? I don’t understand! If I set it to Absent it does the same thing, which is fine, but why is it doing it when it is set to present????

I feel like this is a good place to stop for now so I can think a little about this and try to figure out what is going on.