本文介绍了Powershell Get-WebSite名称参数被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用PowerShell Get-Website cmdlet检索有关特定IIS 7网站的信息.不幸的是,无论我传入的-Name参数如何,Get-Website都会返回所有网站的信息.看来-Name参数被忽略了.

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.

例如,如果我使用:

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

根据文档Get-Website,应返回-Name参数中指定的网站的信息.我一定是误解了文档或误用了cmdlet,或者两者兼而有之.

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.

我应该如何使用Get-Website返回特定网站的信息?

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

推荐答案

根据此论坛发布,这是Get-Website cmdlet中的错误.解决此问题之前的解决方法是使用Get-Item.

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.

这篇关于Powershell Get-WebSite名称参数被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 22:51