我想使用PowerShell Get-Website cmdlet检索有关特定IIS 7网站的信息。不幸的是,Get-Website返回所有网站的信息,而不管我传入的-Name参数。看起来-Name参数被忽略。
例如,如果我使用:
- Import-Module WebAdministration
- Get-Website -Name "Test Website"
我将收到我机器上所有网站的信息:
- Name ID State Physical Path Bindings
- ---- -- ----- ------------- --------
- Default Web Site 1 Started %SystemDrive%\inetpub\wwwroot http *:80:
- net.tcp 808:*
- net.pipe *
- net.msmq localhost
- msmq.formatname localhost
- Test Website 2 Started C:\websites\test http *:80:test.mydomain.com
根据文档Get-Website应该返回-Name参数中指定的网站的信息。我必须误解文档或误用该cmdlet,或两者兼而有之。
如何使用Get-Website来返回特定网站的信息?
根据
this forum post,这是Get-Website cmdlet中的一个错误。解决这个问题的方法是使用Get-Item。
- $website = "Test"
- Get-Item "IIS:\sites\$website"
确保使用双引号,当使用单引号时,变量不会扩展。