PowerShell v3 Function Get WebServerInformation

Following on the heels of my last post, Test-Uri, this function provides a canned function to test web responses. As part of the CodePlex module for PowerShell security I am working on, this function works to gather key details about servers you may be contacting. Its quite long, but, the majority of it is just parameter definition and if statements.
function Get-WebServerInformation
{
      <#
            .NOTES
                  Author: Will Steele
                 
            .EXAMPLE
                  Get-WebServerInformation -Uri http://www.microsoft.com -All
                 
                  IsMutuallyAuthenticated : False
                  Cookies                 : {}
                  Headers                 : {Accept-Ranges, Content-Length, Cache-Control, Content-Type...}
                  SupportsHeaders         : True
                  ContentLength           : 1020
                  ContentEncoding         :
                  ContentType             : text/html
                  CharacterSet            : ISO-8859-1
                  Server                  : Microsoft-IIS/7.5
                  LastModified            : 3/16/2009 3:35:26 PM
                  StatusCode              : OK
                  StatusDescription       : OK
                  ProtocolVersion         : 1.1
                  ResponseUri             : http://www.microsoft.com/
                  Method                  : GET
                  IsFromCache             : False
                 
            .EXAMPLE
                  Get-WebServerInformation -Uri http://www.google.com -CharacterSet
                 
                  ISO-8859-1
                 
            .EXAMPLE
                  Get-WebServerInformation -Uri http://www.kofax.com -StatusCode -CharacterSet
                 
                  ISO-8859-1
                  OK
                 
            .PARAMETER -Uri
                  A required parameter indicating the URI of the remote server.
      #>
     
      [CmdletBinding()]
      param(
            [Parameter(
                  Mandatory = $true,
                  Position = 1,
                  ValueFromPipeline = $true
            )]
            [ValidateScript({Test-Uri -Uri $_})]
            [String]
            $Uri,
           
            [Switch]
            $All = $false,
           
            [Switch]
            $CharacterSet = $false,
                       
            [Switch]
            $ContentEncoding = $false,

            [Switch]
            $ContentLength = $false,           
           
            [Switch]
            $ContentType = $false,
           
            [Switch]
            $Cookies = $false,           
           
            [Switch]
            $Headers = $false,
           
            [Switch]
            $IsFromCache = $false,       
           
            [Switch]
            $IsMutuallyAuthenticated = $false,
           
            [Switch]
            $LastModified = $false,
           
            [Switch]
            $Method = $false,            
           
            [Switch]
            $ProtocolVersion = $false,
           
            [Switch

Related Posts by Categories

0 comments:

Post a Comment