Powershell Get-WebSite name parameter is ignored

11,998

Solution 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.

Solution 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' }

Solution 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*"
Share:
11,998
Ryan Taylor
Author by

Ryan Taylor

Updated on June 06, 2022

Comments

  • Ryan Taylor
    Ryan Taylor almost 2 years

    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?

  • Rich
    Rich over 13 years
  • LosManos
    LosManos about 12 years
    Just for clarity and newbies (like me): there is no need to declare a variable.
  • Mels
    Mels over 8 years
    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.
  • Marcus
    Marcus over 8 years
    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.