IIS在Powershell中启用HTTP Keep-Alive

时间:2013-08-23 12:52:53

标签: iis powershell wmi keep-alive

页面http://technet.microsoft.com/en-us/library/cc772183(v=ws.10).aspx说明了如何启用HTTP保持活动响应标头(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属性的正确方法是什么?

2 个答案:

答案 0 :(得分:4)

您还可以使用Set-WebConfiguration cmdlet设置它:

Set-WebConfiguration -Filter system.webServer/httpProtocol -PSPath MACHINE/WEBROOT/APPHOST -Value @{allowKeepAlive=$true}

答案 1 :(得分: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()