Class-Defined DSC resource does not get imported

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of sirirako sirirako 1 year, 8 months ago.

  • Author
    Posts
  • #23649
    Profile photo of sirirako
    sirirako
    Participant

    My first class-defined resource is called AppHost. I created it and put it here.

    Directory: C:\Program Files\WindowsPowerShell\Modules\apphost

    Mode LastWriteTime Length Name
    —- ————- —— —-
    -a—- 3/24/2015 5:07 PM 6588 AppHost.psd1
    -a—- 3/24/2015 10:29 PM 2005 AppHost.psm1

    When I imported it in the configuration, it recognizes the module AppHost (Import-DscResource -ModuleName AppHost does not have the red line under it) but when I try to use the resource (which is the class name), it shows the red line says Undefined resource and it need to be imported. What could be a problem?

    enum Ensure
    {
        Absent
        Present
    }
    [DscResource()]
    class IISAppHost
    {
        [DscProperty(Key)]
        [string] $name
    
        [DscProperty(Mandatory)]
        [Ensure] $Ensure
    
        [DscProperty(Mandatory)]
        [string] $filter
    
        [DscProperty(Mandatory)]
        [string] $value
    
    
    
    [void] Set()
    {
        $existingvalue = Get-WebConfigurationProperty -Filter $this.filter -Name $this.name -PSPath IIS:\
        $setvalue = $this.value
    
        if($this.Ensure -eq [Ensure]::Present)
        {
            if (($existingvalue.Length -eq 0) -or ($existingvalue -ne $setvalue))
            {
                if ($existingvalue -isnot [string])
                {
                    $newValue = $setvalue -as $existingvalue.GetType()
                }
                Write-Verbose -Message "Setting attribute name, $this.name, value, $this.value, at $this.filter"
                Set-WebConfigurationProperty -Filter $this.filter -Name $this.name -PSPath IIS:\ -Value $setvalue
            }
        }
        else
        {
            
        }
    
    }
    [bool] Test()
    {
        $existingvalue = Get-WebConfigurationProperty -Filter $this.filter -Name $this.name -PSPath IIS:\
        $setvalue = $this.value
        
        if ($this.Ensure -eq [Ensure]::Present)
        {
            if (($existingvalue.Length -eq 0) -or ($existingvalue -ne $setvalue))
            {
                return $false
            }
            else
            {
                return $true
            }
        }
        else
        {
            if(($existingvalue.Length -eq 0))
            {
                return $true
            }
            else
            {
                return $false
            }
        }
    
        
    }
    [IISAppHost] Get()
    {
        $existingvalue = Get-WebConfigurationProperty -Filter $this.filter -Name $this.name -PSPath IIS:\
    
        if ($existingvalue.Length -eq 0) 
        {
            $this.Ensure = [Ensure]::Absent
            $this.value = $existingvalue
        } 
        else
        {
            $this.Ensure = [Ensure]::Present
            $this.value = $existingvalue   
        }
        return $this
    
    }
    
    
    
    Configuration WebConfig 
    {   
        Import-DscResource -ModuleName cIISBaseConfig
        Import-DscResource -ModuleName xPSDesiredStateConfiguration
        Import-DscResource -ModuleName AppHost
        Node $Allnodes.Where{$_.Web -eq $true}.NodeName
        {
           [u] IISAppHost[/u] queueLenght
            {
                Ensure = "Present"
                Filter = "/system.applicationHost/applicationPools/applicationPoolDefaults"
                Name = "queueLength"
                Value = "10005"
    
            }
         }
    
    }
    
    
  • #23650
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Best guess based on the info so far: you haven't added 'IISAppHost' to your DscResourcesToExport property in the module manifest.

  • #23651
    Profile photo of sirirako
    sirirako
    Participant

    You're right! Once again, Dave, thank you very much! I didn't realize that the command New-ModuleManifest didn't add that property so I missed it.

You must be logged in to reply to this topic.