【问题标题】:IIS Enable the HTTP Keep-Alive in PowershellIIS 在 Powershell 中启用 HTTP Keep-Alive
【发布时间】:2013-08-26 12:55:38
【问题描述】:

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 属性的正确方法是什么?

【问题讨论】:

    标签: iis powershell wmi keep-alive


    【解决方案1】:

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

    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()
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 非常感谢,谢伊。我最终使用了这个解决方案,尽管它不像我最初询问的那样基于 WMI。像我这样的新手需要运行的唯一一件事是:Import-Module WebAdministration。此外,可能以下命令更简单: Set-WebConfigurationProperty "/system.webServer/httpProtocol" -name allowKeepAlive -value "true"
      • 是的,我应该提到 Import-Module :)
      • 我收到“在此对象上找不到属性 'AllowKeepAlive'。验证该属性是否存在并且可以设置。”一切似乎都很好。想法? AllowKeepAlive 属性 bool AllowKeepAlive {get;set;}
      猜你喜欢
      • 1970-01-01
      • 2012-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-14
      • 1970-01-01
      • 2014-01-12
      • 2012-09-15
      相关资源
      最近更新 更多