Class Requires Value of type MSFT_Credential

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Jacob Benson Jacob Benson 2 years, 5 months ago.

  • Author
    Posts
  • #16452
    Profile photo of Jacob Benson
    Jacob Benson
    Member

    I am writing (or trying) to write a Custom Resource that uses a Credential parameter. The Test-Schema and Test-Resource cmdlets all return true. However, when I go to invoke the Configuration, I get this error:

    cSCVMM\cSCVMM_Hardware : Class 'cSCVMM_Hardware' requires that a value of type 'MSFT_Credential' be provided for property 'Credential'.
    At line:13 char:9
    +         cSCVMM_Hardware MyHardwareProfile
    +         ~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [Write-Error], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : MissingValueForMandatoryProperty,cSCVMM\cSCVMM_Hardware
     
    Errors occurred while processing configuration 'TestSCVMMHardware'.
    At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:2203 char:5
    +     throw $errorRecord
    +     ~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (TestSCVMMHardware:String) [], InvalidOperationException
        + FullyQualifiedErrorId : FailToProcessConfiguration
    

    My schema.mof contains this line:

    [Required, EmbeddedInstance("MSFT_Credential"), Description("Valid credential for connecting to VMM Server")] String Credential;

    Comparing the schema and .psm1 file to those of the ADDomain resource, I can't see what the issue is. I looked to see if any of Steve Murawski's Stack Exchange Resources use a credential parameter, and the Scheduled Task one does. I tried changing my Credential parameter in all 3 functions to what his is in that resource, but I still got the same error. He has his credential set like this:

    $Credential = [System.Management.Automation.PSCredential]::Empty

    Here is what my Configuration looks like.

    Configuration TestSCVMMHardware
    {
    
        param
        (
            [PSCredential]$Credential
        )
    
        Import-DscResource -Module cSCVMM
    
        node localhost
        {
            cSCVMM_Hardware MyHardwareProfile
            {
                VMMServer = "MY-VMM-SERVER1"
                CPUCount = 2
                DVDDrive = $True
                Ensure = "Present"
                Name = "Jacobs Profile"
                VMNetwork = "Server Traffic"
           }
    
        }
    
    }
    
    TestSCVMMHardware -Credential (Get-Credential domain\name)
    

    I have tried using 2 different domain credentials, and don't have any more ideas. What am I doing wrong?

  • #16454
    Profile photo of Jason Hofferle
    Jason Hofferle
    Participant

    I was just messing around with this same exact thing today. It looks like you're passing the credential to your configuration, but not to the resource that needs the credential. Have you tried:

            cSCVMM_Hardware MyHardwareProfile
            {
                VMMServer = "MY-VMM-SERVER1"
                CPUCount = 2
                DVDDrive = $True
                Ensure = "Present"
                Name = "Jacobs Profile"
                VMNetwork = "Server Traffic"
                Credential = $Credential
           }
    
  • #16456
    Profile photo of Jacob Benson
    Jacob Benson
    Member

    Ah hell. You are absolutely correct. I was so convinced I had screwed up something with the Resource that I failed to see the obvious. Thanks Jason!

You must be logged in to reply to this topic.