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">
        <binding protocol="http" bindingInformation=":8081:"/>
        <binding protocol="https" bindingInformation=":8082:"/>

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.


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) { 
  New-Item ...
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.