Functions/Private/Get-UrlMetaData.ps1
function Get-UrlMetadata { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification='MetaData is singular and plural')] [cmdletbinding()] param ( [string] $url ) Write-Verbose "Get-UrlMetaData-Getting response" [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12 -bor [System.Net.SecurityProtocolType]::Tls13; $HttpResponse =$null try{ $HttpResponse = Get-WebRequestResponse -url $url Write-Verbose "Fetching file from $url ..." Convert-UrlResponseToMetaData $HttpResponse Write-Verbose "Got filename: $($HttpResponse.ResponseUri.Segments[-1]), Size: $($HttpResponse.ContentLength)" } catch{ write-host $_.Exception.InnerException throw } finally { Write-Verbose "Disposing of webrequest response." if ($null -ne $HttpResponse){ $HttpResponse.Close() $HttpResponse.Dispose() } } } function Get-WebRequestResponse (){ [CmdletBinding()] param ( [string] $url) write-verbose "security protocol = $([System.Net.ServicePointManager]::SecurityProtocol)" [System.Net.WebRequest]::Create($url).GetResponse(); } |