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.