Question

The page http://technet.microsoft.com/en-us/library/cc772183(v=ws.10).aspx explains how to Enable the HTTP Keep-Alive Response Header (IIS 7)

I want to do this in Powershell by WMI

It says:

Use the following WMI classes, methods, or properties to perform this procedure: HTTPProtocolSection.AllowKeepAlive property

I've tried:

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

What's the right way of using this HTTPProtocolSection class and enabling AllowKeepAlive property?

Was it helpful?

Solution 2

To discover class in a particular namespace try this

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

and to find a match do this

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

You can then do something like this to get the value of 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()

OTHER TIPS

You can also set it with the Set-WebConfiguration cmdlet:

Set-WebConfiguration -Filter system.webServer/httpProtocol -PSPath MACHINE/WEBROOT/APPHOST -Value @{allowKeepAlive=$true}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top