Public/Functions/split/Test-WebConnection.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
<#
.SYNOPSIS Tests to see if a Uri by Invoke-WebRequest -Method Head .DESCRIPTION Tests to see if a Uri by Invoke-WebRequest -Method Head .LINK https://osd.osdeploy.com/module/functions/webconnection #> function Test-WebConnection { [CmdletBinding()] param ( [Parameter(ValueFromPipeline)] # Uri to test [System.Uri] $Uri = 'google.com' ) $Params = @{ Method = 'Head' Uri = $Uri UseBasicParsing = $true Headers = @{'Cache-Control'='no-cache'} } try { Write-Verbose "Test-WebConnection OK: $Uri" Invoke-WebRequest @Params | Out-Null $true } catch { Write-Verbose "Test-WebConnection FAIL: $Uri" $false } finally { $Error.Clear() } } |