1

I'm pretty new to PowerShell so I'm not entirely sure what the correct terminology is for what I want to do, but hopefully a description will suffice. I'm trying to use the Web-Administration module to set up websites, with configuration in an XML file.

A website config section looks like:

<WebSite name="Test" destination="WebServers">
<physicalPath>c:\temp</physicalPath>
    <bindings>
        <binding protocol="http" bindingInformation=":8081:"/>
        <binding protocol="https" bindingInformation=":8082:"/>
    </bindings>
</WebSite>

I have loaded this into an [xml] variable, and can traverse it.

I know I can create a website with something like:

New-Item <SiteName> -bindings (@{protocol="http";bindingInformation="*:80:DemoSite1"},@{protocol="http";bindingInformation="*:80:DemoSite2"}) -PhysicalPath <PhysicalPath>

Is there an easy (one-liner) that I can use to turn the bindings in the XML into something that I can pass to the bindings parameter of New-Item? I feel like there must be a more concise way to do this than explicitly iterating over the binding elements.

Alternatively, is there some completely other method I should be using to do this? I know about the New-Website cmdlet, but using it doesn't seem to make anything much easier.

AwesomeTown
  • 153
  • 7

1 Answers1

1

The Get-Content commandlet will let you read the XML into a variable that you can then use to populate the website creation call to new-item.

[xml]$WebSites = Get-Content WebSites.xml

and then

foreach( $site in $WebSites.WebSite) { 
  $path=$site.physicalPath
  ..etc 
  New-Item ...
}
Helvick
  • 20,019
  • 4
  • 38
  • 55
  • Sorry... I understand how to load/traverse the XML. What I'm wondering is if there is a more concise way to take the XML representation of the bindings and turn it into the object representation that New-Item accepts, rather than explicitly iterating over the bindings. – AwesomeTown Sep 13 '10 at 19:50