Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 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 ...
}
share|improve this answer
    
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. –  John Price Sep 13 '10 at 19:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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