1

该页面http://technet.microsoft.com/en-us/library/cc772183(v=ws.10).aspx解释了如何启用 HTTP Keep-Alive 响应标头 (IIS 7)

我想通过 WMI在Powershell中执行此操作

它说:

使用以下 WMI 类、方法或属性来执行此过程: HTTPProtocolSection.AllowKeepAlive属性

我试过了:

PS > Get-WmiObject -Class HTTPProtocolSection
Get-WmiObject : Invalid class
At line:1 char:14
+ Get-WmiObject <<<<  -Class HTTPProtocolSection
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

使用此 HTTPProtocolSection 类并启用 AllowKeepAlive 属性的正确方法是什么?

4

2 回答 2

4

您也可以使用Set-WebConfigurationcmdlet 进行设置:

Set-WebConfiguration -Filter system.webServer/httpProtocol -PSPath MACHINE/WEBROOT/APPHOST -Value @{allowKeepAlive=$true}
于 2013-08-23T16:41:23.590 回答
2

要发现特定命名空间中的类,试试这个

PS c:\>Get-WmiObject -List * "root\webadministration" 

并找到匹配项

PS c:\>Get-WmiObject -List * "root\webadministration" | Where-Object {$_.name -match "Http"}


PS C:\>Get-WmiObject -Namespace "root\webadministration" -class HttpProtocolSection | Get-Member

TypeName: System.Management.ManagementObject#root\webadministration\HttpProtocolSection

Name                MemberType    Definition
----                ----------    ----------
PSComputerName      AliasProperty PSComputerName = __SERVER
Add                 Method        System.Management.ManagementBaseObject Add(System.String CollectionName, System.Ma...
Clear               Method        System.Management.ManagementBaseObject Clear(System.String CollectionName)
Get                 Method        System.Management.ManagementBaseObject Get(System.String CollectionName, System.St...
Remove              Method        System.Management.ManagementBaseObject Remove(System.String CollectionName, System...
RevertToParent      Method        System.Management.ManagementBaseObject RevertToParent(System.String PropertyName)
AllowKeepAlive      Property      bool AllowKeepAlive {get;set;}
CustomHeaders       Property      System.Management.ManagementObject#CustomHeaderSettings CustomHeaders {get;set;}
Location            Property      string Location {get;set;}
Path                Property      string Path {get;set;}
RedirectHeaders     Property      System.Management.ManagementObject#RedirectHeaderSettings RedirectHeaders {get;set;}
SectionInformation  Property      System.Management.ManagementObject#SectionInformation SectionInformation {get;set;}
__CLASS             Property      string __CLASS {get;set;}
__DERIVATION        Property      string[] __DERIVATION {get;set;}
__DYNASTY           Property      string __DYNASTY {get;set;}
__GENUS             Property      int __GENUS {get;set;}
__NAMESPACE         Property      string __NAMESPACE {get;set;}
__PATH              Property      string __PATH {get;set;}
__PROPERTY_COUNT    Property      int __PROPERTY_COUNT {get;set;}
__RELPATH           Property      string __RELPATH {get;set;}
__SERVER            Property      string __SERVER {get;set;}
__SUPERCLASS        Property      string __SUPERCLASS {get;set;}
ConvertFromDateTime ScriptMethod  System.Object ConvertFromDateTime();
ConvertToDateTime   ScriptMethod  System.Object ConvertToDateTime();

然后你可以做这样的事情来获取 AllowKeepAlive 的值

PS C:\> (get-wmiobject -namespace "root\webadministration" -class HttpProtocolSection).AllowKeepAlive 
True

PS C:\>$a = Get-WmiObject -Namespace "root\webadministration" -class HttpProtocolSection
PS C:\>$a.AllowKeepAlive = $false
PS C:\>$a.Put()
于 2013-08-23T14:30:28.990 回答