$Node.App.Foreach - Where am i going wrong.

Hi,
I have a basic DSC script to create IIS AppPools and i’m try to create a foreach loop from Data within a CSV file.



# Nodes
$Nodes = @(
@{NodeName = "HQWEBSERVER01";Role = "IIS";PSDscAllowPlainTextPassword = $true},
@{NodeName = "HQAPPSERVER01";Role = "APP";PSDscAllowPlainTextPassword = $true},
@{Nodename = "*";Features = "Web-Mgmt-Tools","WEb-Scripting-Tools" , "Web-Mgmt-Service";AppPools = Import-Csv C:\ScriptOutput\groups.csv}
)
$Configuration = @{AllNodes = $Nodes;PSDscAllowPlainTextPassword = $true}


Configuration DSC_WebServer_Build {
param()
Import-DscResource -ModuleName "PSDesiredStateConfiguration"
Import-DscResource -ModuleName "xSecEdit"
Import-DscResource -ModuleName "xSMBShare"
Import-DscResource -ModuleName "cNtfsAccessControl"
Import-DscResource -ModuleName "xWebAdministration"

Node $AllNodes.Where({$_.Role -EQ "IIS"}).NodeName
{
$Node.Features.Foreach({
    
WindowsFeature $_
        {
            Name = $_
            Ensure = "Present"  
        } # END of WindowsFeatures
     #END of Foreach Node configuration

    })# END of all Nodes feature configuration

$Node.AppPools.AppPool.foreach({
    xWebAppPool $_
        {
            Name = $_
            Ensure = "Present"
            State = "Started"
            identityType = "SpecificUser"
            Credential = $DocCreds
        }
})
}
}

DSC_WebServer_Build -ConfigurationData $Configuration -OutPutPath "C:\ScriptOutput\DSC\WebServer_Build"

So within the CSV is a load of data, with one column containing AppPool names. So i want to get the name of the app pool and create xWebAppPool entry for every AppPool in the CSV.

But when i run the the build it errors:
An exception was raised while processing Node ‘HQWEBSERVER01’: Index operation failed; the array index evaluated to null.

I cant see where i’m going wrong?

Hope this makes sense?

Cheers

TommyQ

what happens if you replace node selection logic in line 34 with the one below?

$allnodes.AppPools.Appool

Hi Sergei,

Thanks for the reply, still no good tho. It’s odd because it works fine with the Windows Features.

Cheers

Tom

If I had to guess, I would say ‘AllNodes’ will not actually create the array with “features” for the other objects, try to set the “Features” array in all nodes separately and see if it works.

Hi,

I’ve managed to solve this now, thanks for your replies. The actual issue was because i had a empty entry in the CSV file :frowning:

The error obvious now i know the issue:
“An exception was raised while processing Node ‘HQWEBSERVER01’: Index operation failed; the array index evaluated to null.”