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" } } }