Depends on with variable name

Hi,

I am trying to Powershell configuration in which I have an array of websites.

As I will have multiple websites, I will need to create first a new directory for the respective website, and then create the IIS website and application pool. Here is an example:

#Create the folder
File $Site.Name {
Type = "Directory"
DestinationPath = "$($Allnodes.RootPath)\$($Site.Name)"
Ensure = "Present"
}

#Create Website
xWebsite $Site.Name {
Ensure = 'Present'
Name = $Site.Name
State = $Site.State
PhysicalPath = "$($Allnodes.RootPath)\$($Site.Name)"
ApplicationPool = $Site.AppPool.Name
BindingInfo = @(
MSFT_xWebBindingInformation {
Port = $Allnodes.Aplatform.Website.Bindings.FirstBinding.Port
IPAddress = $Site.Bindings.FirstBinding.IPAddress
HostName = $Site.Bindings.FirstBinding.Hostname
Protocol = $Site.Bindings.FirstBinding.Protocol
}

)
DependsOn = @("[File]$Site.Name",[otherdependencies with variables])

I need that DependsOn just to be sure that the website in IIS is created after the directory is created on the disk. When I try to compile this MOF, I get the following error:

ValidateNodeResources : Resource ‘[File]System.Collections.Hashtable.Name’ required by
‘[xWebsite]SiteName’ does not exist. Please ensure that the required resource exists and the
name is properly formed.

How is the correct way to define the DependsOn when it is a variable? If I use DependsOn with a string [File]CreateDirectory then it works, but I can’t use a static string because on top of this configuration it is a foreach which creates the directory on disc, website, apppool for each website, so they have to be unique.

Thank you

Try using:

DependsOn = @(“[File]$($Site.Name)”,[otherdependencies with variables])

Thank you,

I figured it out eventually, but my post was approved very late :slight_smile:

Appreciate the help.