Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell Get-WebSite name parameter is ignored

Tags:

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?

like image 512
Ryan Taylor Avatar asked Nov 13 '10 02:11

Ryan Taylor


People also ask

What is IEX in PowerShell?

iex is an alias for Invoke-Expression . Here the two backticks don't make any difference, but just obfuscates the command a little. iex executes a string as an expression, even from pipe. Here Start-Process is a cmdlet that starts processes.

How to use Get-Member in PowerShell?

The Get-Member cmdlet gets the members, the properties and methods, of objects. To specify the object, use the InputObject parameter or pipe an object to Get-Member . To get information about static members, the members of the class, not of the instance, use the Static parameter.

How do I get the properties of an object in PowerShell?

To get the properties of an object, use the Get-Member cmdlet. For example, to get the properties of a FileInfo object, use the Get-ChildItem cmdlet to get the FileInfo object that represents a file. Then, use a pipeline operator ( | ) to send the FileInfo object to Get-Member .

How do I create a loop in PowerShell?

The While statement in PowerShell is used to create a loop that runs a command or a set of commands if the condition evaluates to true. It checks the condition before executing the script block. As long as the condition is true, PowerShell will execute the script block until the condition results in false.


2 Answers

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.

like image 52
Ryan Taylor Avatar answered Sep 22 '22 03:09

Ryan Taylor


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' }
like image 39
Marcus Avatar answered Sep 18 '22 03:09

Marcus