直接从Powershell中的XML填充对象

我对PowerShell相当陌生,所以我不完全确定正确的术语是为了我想做什么,但希望描述就足够了。 我正在尝试使用Webpipe理模块来设置网站,并在XML文件中进行configuration。

网站configuration部分如下所示:

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

我已经加载到一个[xml]variables,并可以遍历它。

我知道我可以创build一个像这样的网站:

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

有没有简单的(单行),我可以用来把XML中的绑定转换成可以传递给New-Itembindings参数的东西? 我觉得必须有一个更简洁的方法来做到这一点,而不是显式迭代绑定元素。

另外,是否有一些完全的其他方法,我应该用来做到这一点? 我知道New-Website cmdlet,但使用它似乎没有什么更容易。

Get-Content命令行程序可让您将XML读取到一个variables中,然后您可以使用该variables将网站创build调用填充到新项目中。

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

接着

 foreach( $site in $WebSites.WebSite) { $path=$site.physicalPath ..etc New-Item ... }