Powershell Get-WebSite name parameter is ignored

馋奶兔 提交于 2019-12-08 14:35:35

问题


I want to retrieve information regarding specific IIS 7 website using the PowerShell Get-Website cmdlet. Unfortunately, Get-Website returns information for all websites regardless of the -Name parameter I pass in. It appears that the -Name parameter is ignored.

For instance, if I use:

Import-Module WebAdministration
Get-Website -Name "Test Website"

I will receive information for all websites on my machine:

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

According to the documentation Get-Website should return information for the website specified in the -Name parameter. I must be misunderstanding the documentation or misusing the cmdlet, or both.

How should I use Get-Website to return information for a specific website?


回答1:


According to this forum post, this is a bug in the Get-Website cmdlet. The workaround until this is addressed is to use Get-Item.

$website = "Test"
Get-Item "IIS:\sites\$website"

Be sure to use double quotes, variables are not expanded when single quotes are used.




回答2:


I realize it's an older post but I ran into this issue recently and found your question. I've had luck with the following syntax too:

get-website | where { $_.Name -eq 'foobar' }



回答3:


Using wild cards will also get around this issue as mentioned in the work around in the connect topic referenced by @Joey

get-website -name "*Default Web Site*"


来源:https://stackoverflow.com/questions/4170530/powershell-get-website-name-parameter-is-ignored

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!