Strange error when executing configuration file

This topic contains 3 replies, has 3 voices, and was last updated by  Alexander Johansson 1 month, 3 weeks ago.

  • Author
    Posts
  • #34895

    Wei-Yen Tan
    Participant

    Hi,

    I am trying to use the method of using a configuration parameter to pass to a configuration. This happenss when creating a mof.

    However what i am finding is that i am getting this error:

    `

    PSDesiredStateConfiguration\Configuration : Cannot convert value "False" to type "System.Management.Automation.ScriptBlock". Error: "Invalid cast from 'System.Boolean' to 'System.Management.Automation.ScriptBlock'."
    At C:\Scripts\DSC.ps1:1 char:1
    + Configuration DSC_Example
    + ~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Configuration], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidCastIConvertible,Configuration

    Errors occurred while processing configuration 'DSC_Example'.
    At C:\windows\system32\windowspowershell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:2088 char:5
    + throw $errorRecord
    + ~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (DSC_Example:String) [], InvalidOperationException
    + FullyQualifiedErrorId : FailToProcessConfiguration

    `

    I am not quite sure what this is referring to.....even though I have checked through help and online help.

    Any guidance would be most grateful. I have my code below:

    Configuration DSC_Example 
    {
        param (
            [Parameter(Mandatory)]
         [pscredential]$safemodeAdministratorCred,
            [Parameter(Mandatory)]
        [pscredential]$domainCred,
    	    [Parameter(Mandatory)]
        [pscredential]$DNSDelegationCred,
    	
        [Parameter(Mandatory)]
        [pscredential]$LocalAdminCred
        )
        Import-DscResource -modulename xWebadministration, xActiveDirectory, xFailOverCluster, xcomputermanagement
    
    
      
       
    
            #Specifing configurations for each server. Specifying resource blocks.
    
            node $Allnodes.Where($_.role -eq "ADServer").nodename
            {
                WindowsFeature ADDSInstall
                {
                    Ensure = "Present"
                    Name = "AD-Domain-Services"
                }
                xADDomain FirstDS
                {
                    DomainName = $Node.DomainName
                    DomainAdministratorCredential = $domainCred
                    SafemodeAdministratorPassword = $safemodeAdministratorCred
                    DnsDelegationCredential = $DNSDelegationCred
                    DependsOn = "[WindowsFeature]ADDSInstall"
                }
        
    
                WindowsFeature Graphical_Interface_Uninstall
                {
                    Name   ="Server-Gui-Mgmt-Infra"
                    Ensure = "Absent"
                }
            }
    
            node $Allnodes.Where($_.role -eq "Webserver")
            {
                WindowsFeature IIS
                {
                        Name   ="Web-Server"
                        Ensure ="Present"
                }
    
                     
                WindowsFeature IIS_Management_Service
                {
                        Name       = "Web-Mgmt-Service"
                        Ensure     = "Present"
                        DependsOn  = '[WindowsFeature]IIS'
                }
    
               
                WindowsFeature IIS_Management_Service
                {
                        Name       = "Web-Mgmt-Service"
                        Ensure     = "Present"
                        DependsOn  = '[WindowsFeature]IIS'
                }
    
                xWebsite DefaultSite 
                {
                    Ensure          = 'Present'
                    Name            = 'Default Web Site'
                    State           = 'Stopped'
                    PhysicalPath    = 'C:\inetpub\wwwroot'
                    DependsOn       = '[WindowsFeature]IIS'
                }
    
               xcomputer Add_Domain
               {
                    Credential = $LocalAdminCred
                    Dependson  = "[WindowsFeature]ADDSInstall"
               } 
    
              WindowsFeature Graphical_Interface_Uninstall
                {
                    Name   ="Server-Gui-Mgmt-Infra"
                    Ensure = "Absent"
                }
    
            }
    
             node $Allnodes.Where($_.nodename -eq "fs1")
              {
                xCluster FS
                    
                 {
                        DomainADministratorCredential = $domainCred
                        Name = "Failover"
                        StaticIPAddress = "192.168.1.111"
                 }
    
               WindowsFeature Graphical_Interface_Uninstall
                {
                    Name   ="Server-Gui-Mgmt-Infra"
                    Ensure = "Absent"
                }
    
              }
     
     }
     
  • #34941

    Wei-Yen Tan
    Participant

    I have revised the syntax and the layout of the original format and everything is looking good.

    I segmented everything into individual roles and then everything started working from there...

    This was for a lab and I just wanted to test that it was working with the design that I have above (getting things from a configurationfile.psd1).

    Yay! Now onto the next one.

  • #82790

    Michael G. Mayoral
    Participant

    I'm having the exact same issue right now. Could you please expand a little more on how you resolved this?

    • #101121

      Alexander Johansson
      Participant

      I know this is an old thread but I might aswell point out one obvious error in this configuration, which would generate this exact error. Also, if someone else is finding this thread they might be interested.

      At line 22 he is doing the following:

      node $Allnodes.Where($_.role -eq "ADServer").nodename

      When the 'Where' query should be enclosed with {} and not (), like this:

      node $Allnodes.Where{$_.role -eq "ADServer"}.nodename

      /Alexander

You must be logged in to reply to this topic.