I am trying to create multiple app pools using DSC. If I try to make the $AppPoolName accept an array I get the error:
Exception calling "ValidateInstanceText" with "1" argument(s): "Convert property 'Name' value from type 'STRING[]' to type 'STRING' failed. It does work if I do the below and only accept one app pool
Configuration Sample_xWebAppPool
{
param
(
[parameter(Mandatory)]
[String]
$AppPoolName,
[ValidateSet("Started", "Stopped")]
[string]
$state="Started",
[String[]]
$NodeName = 'localhost'
)
Import-DscResource -ModuleName xWebAdministration
Node $NodeName
{
xWebAppPool $AppPoolName
{
Name = $AppPoolName
Ensure = 'Present'
State = $state
autoStart = $true
idleTimeout = (New-TimeSpan -Minutes 20).ToString()
restartPrivateMemoryLimit = 700000
logEventOnRecycle = 'Time,Memory,PrivateMemory'
}
}
}
Sample_xWebAppPool -NodeName "server" -state started -AppPoolName "AppPool1"
I want to be able to do this sort of thing:
Sample_xWebAppPool -NodeName "server" -state started -AppPoolName "AppPool1","AppPool2","AppPool3"
I'm not sure if this is the correct way or best way of doing this.
I found that this works:
Configuration Sample_xWebAppPool
{
param
(
[parameter(Mandatory)]
[String[]]
$AppPoolName,
[ValidateSet("Started", "Stopped")]
[string]
$state="Started",
[String[]]
$NodeName = 'localhost'
)
Import-DscResource -ModuleName xWebAdministration
Node $NodeName
{
foreach($AppPool in $AppPoolName) {
xWebAppPool $AppPool
{
Name = $AppPool
Ensure = 'Present'
State = $state
autoStart = $true
idleTimeout = (New-TimeSpan -Minutes 20).ToString()
restartPrivateMemoryLimit = 700000
logEventOnRecycle = 'Time,Memory,PrivateMemory'
}
}
}
}
Sample_xWebAppPool -NodeName "server" -state started -AppPoolName "AppPool1", "AppPool2", "AppPool3"
Make you AppPoolName parameter a string array and add a foreach to the xWebAppPool creation.