PowerShell Script to Get HTTP Headers

Quick script to grab HTTP headers from a given URL.

I named the script Get-HTTPHeaders.ps1, you can save it as whatever you’d like, or, incorporate it into your script as a function, or not even read this post… whatever you want to do. I just find it handy, and wanted to share it.

param(
    [Parameter(ValueFromPipeline=$true)]
    [string] $Url
)

$request = [System.Net.WebRequest]::Create( $Url )
$headers = $request.GetResponse().Headers
$headers.AllKeys |
     Select-Object @{ Name = "Key"; Expression = { $_ }},
     @{ Name = "Value"; Expression = { $headers.GetValues( $_ ) } }

All you have to do is pass it a URL as a parameter. See the example below:

image

Advertisement

About Geoff Varosky
Geoff Varosky is a Senior Architect for Insight, based out of Watertown, MA. He has been architecting and developing web based applications his entire career, and has been working with SharePoint for the past 15 years. Geoff is an active member of the SharePoint community, Co-Founder and Co-Organizer of the Boston Area SharePoint Users Group, co-founder for the Boston Office 365 Users Group, co-organizer for SharePoint Saturday Boston and speaks regularly at SharePoint events and user groups.

2 Responses to PowerShell Script to Get HTTP Headers

  1. Doesn’t seem to work with https and self signed certs.
    Is there an easy way to bypass the cert check?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: