PowerShell Script to Get HTTP Headers
February 2, 2018 2 Comments
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:
Doesn’t seem to work with https and self signed certs.
Is there an easy way to bypass the cert check?
I have not tested this, nor do I have direct access to a site with a self-signed cert presently. If you have an example, I could investigate and update the script.