20

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?

Ryan Taylor
  • 8,740
  • 15
  • 65
  • 98

3 Answers3

27

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.

Ryan Taylor
  • 8,740
  • 15
  • 65
  • 98
  • Side note: [Connect topic on that bug](http://connect.microsoft.com/PowerShell/feedback/details/597787/get-website-always-returns-full-list-of-web-sites) – Joey Nov 14 '10 at 00:29
  • Just for clarity and newbies (like me): there is no need to declare a variable. – LosManos Apr 10 '12 at 07:12
13

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' }
Marcus
  • 231
  • 2
  • 4
  • The problem with this workaround is that _all_ websites are listed and then filtered. Not much of a when you've got a handful of websites, but some of us legitimately have _lots_ of websites in a single IIS server. – Mels Dec 09 '15 at 11:35
  • True, it does return all sites then filter. I would prefer filtering left and formatting right but that wasn't an option which is the reason I had to do this workaround. I also had 200-300 sites per server and it wasn't a huge delay running this command. – Marcus Jan 04 '16 at 22:35
7

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*"
Chris Magnuson
  • 5,780
  • 7
  • 34
  • 37