On line 11, use the $uri variable like you use on line 24. Your script is currently using the redirected address from the response. If you don't want that, then use the address that you used on the Invoke-WebRequest.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
In my script the url for example is www.example.123456789 that I need to check, after I ran the script. from the output in csv file, the www.example.123456789 will appear differently this is due to PINGID SSO randomized URL. Is there a solution for that like, in the URL I can add the name of the URL that when I run, it will not be read but only the URL but it will show on CSV? Or do you have a better suggestion please? as if the URL changed every time it runs, it will be difficult to identify what website it is from the CSV file. Thanks
On line 11, use the $uri variable like you use on line 24. Your script is currently using the redirected address from the response. If you don't want that, then use the address that you used on the Invoke-WebRequest.
Hi @Andreas Baumgarten , Below is the code I use and please see the output at the bottom part. Thanks
$Uris = Get-Content -Path "C:\Check\Websites.txt"
$PathTxt = "C:\Check\\Uri.txt"
$PathCsv = "C:\Check\\Uri.csv"
$uriList = @()
foreach ($uri in $Uris) {
$uriObject = New-Object PSObject
$Response = ""
try {
$Response = Invoke-WebRequest -UseDefaultCredentials -Uri $uri -ErrorAction SilentlyContinue -UseBasicParsing -DisableKeepAlive
$uriObject | Add-Member -MemberType NoteProperty -Name "URL" -Value $Response.BaseResponse.ResponseUri
$uriObject | Add-Member -MemberType NoteProperty -Name "Status" -Value $Response.StatusCode
if ($($Response.StatusDescription)) {
$uriObject | Add-Member -MemberType NoteProperty -Name "Description" -Value $Response.StatusDescription
}
else {
$uriobject | Add-Member -MemberType NoteProperty -Name "Description" -Value "OK"
}
Write-Host $Response.StatusCode $Response.StatusDescription $Response.BaseResponse.ResponseUri -ForegroundColor Green
$uriList += $uriObject
}
catch {
Write-Host "Unable to reach $uri" -ForegroundColor Red
$uriObject | Add-Member -MemberType NoteProperty -Name "URL" -Value $uri
$uriObject | Add-Member -MemberType NoteProperty -Name "Status" -Value "Not Responding"
$uriObject | Add-Member -MemberType NoteProperty -Name "Description" -Value "Error"
$uriList += $uriObject
}
}
$uriList | Out-File -FilePath $PathTxt
$uriList | Export-Csv -Path $PathCsv -NoTypeInformation
Below left is the Website.txt and the one on the right (yellow) is the Uri.csv that changes randomly when I ran the website check. This is due to PINGID SSO feature. I want to have a solution wherein if I ran the script I would easily identify that the one on csv file is www.google.com.
Hi @MotoX80 , thanks for you advice. It's way better now. It shows the exact link on the Description. Unlike before some random links that is hard to identify. Thanks a lot! :-)