foreach loop for msi install

trying to figure out this DSC. Please help.

I need to modify it so it can install a MSI to server that fit a server ROLE and ENVIRONMENT.

the ps1 file right now uses the roles:

foreach ($Package in $Node.Packages)
{
$PackageName = “Coresoftware” + $Package.ShortName
if (($Pack.Role -eq $Node.Role) -or ($Pack.Role -eq $null))
{
Write-Verbose “Configuring Package $($Package.Name) for roles ‘$($Pack.Role)’ on node with role $($Node.Role)”
Package $PackageName
{
Name = $Package.Name
Path = $Package.Path
Arguments = $Package.Arguments
ProductID = $Package.ProductID
Ensure = “Present”
}
}
}

the pSD1 file has:

AllNodes = @(
@{
NodeName = “*”
for some common features being installed but then has the other applications only installed on particular server that fit a ROLE.

@{ shortname = ‘MUD’
Name = ‘software name here’
Path = ‘\fileserverlocatition.msi’
ProductID = ‘55555-5555-5555-5555-55555555555555’
Role = ‘web’
}

not sure what to adjust under the foreach loop to look for the environment as well as the role.
and then would I need to add the ENVIRONMENT line to the end like ENVIRONMENT = "Development’

thanks

I do not fully understand the question so if you can elloborate more, I would be able to provide a better answer. But if you want to generate configuration based on two entities, this is how your sample may look like:
configuration foo
{
Node $AllNodes.Where{$_.Environment -eq “Test”}.NodeName
{
foreach ($Package in $Node.Packages)
{
$PackageName = “Coresoftware” + $Package.ShortName
if (($Package.Role -eq $Node.Role) -or ($Package.Role -eq $null))
{
package $PackageName
{
name = $Package.Name
Path = $Package.PAth
Ensure = ‘Present’
ProductId = $Package.ProductId
}
}
}
}
}
foo
$configData = @{
AllNodes = @(
@{
nodename=“localhost”
shortname=“MUD”
Role=“WEB”
Environment = “Test”
Packages = @(
@{Name=“software name here”; Path=‘\fileserverlocatition.msi’;ProductId=“55555-5555-5555-5555-55555555555555”;Role=“WEB”}
)
}
)
}

foo -ConfigurationData $configData

right now the foreach section looks at one variable the “role” I was hoping to get it to look at two variables “role” and “environment”.

@{ shortname = ‘MUD’
Name = ‘software name here’
Path = ‘\fileserverlocatition.msi’
ProductID = ‘55555-5555-5555-5555-55555555555555’
Role = ‘web’
environment = “develop”
}

It could be done in same way.
configuration foo
{
Node $AllNodes.Where{$_.Environment -eq “Test”}.NodeName
{
foreach ($Package in $Node.Packages)
{
$PackageName = “Coresoftware” + $Package.ShortName
if (($Package.Role -eq $Node.Role) -and ($Package.Environment -eq $Node.Environment))
{
package $PackageName
{
name = $Package.Name
Path = $Package.PAth
Ensure = ‘Present’
ProductId = $Package.ProductId
}
}
}
}
}
foo
$configData = @{
AllNodes = @(
@{
nodename=“localhost”
shortname=“MUD”
Role=“WEB”
Environment = “Test”
Packages = @(
@{Name=“software name here”; Path=‘\fileserverlocatition.msi’;ProductId=“55555-5555-5555-5555-55555555555555”;Role=“WEB”;Environment=“Test”}
)
}
)
}

foo -ConfigurationData $configData