I want to take the http status of multiple URL at once to prepare a report. How to acheive it using powershell?
Asked
Active
Viewed 1.1k times
0

Dharman
- 30,962
- 25
- 85
- 135

Singaramani Thangavel
- 185
- 1
- 1
- 12
-
3I'm voting to close this question as off-topic because StackOverflow is not a blogging website. There is no question here that people can answer. While you might find other post like this on the network it is not something that is encouraged. If you wanted to present a code based problem (up to normal question standards mcve etc) and answer it with this code that would be better. – Matt Oct 10 '18 at 12:45
1 Answers
3
I have seen questions on monitoring multiple websites through windows machine. My friend wanted to check status of 200 URLs which he used to do manually. I wrote a Power-Shell script to overcome this. Posting it for the benefit of all users.
Save the below code as "AnyName.ps1" file in "D:\MonitorWeb\"
#Place URL list file in the below path
$URLListFile = "D:\MonitorWeb\URLList.txt"
$URLList = Get-Content $URLListFile -ErrorAction SilentlyContinue
#For every URL in the list
Foreach($Uri in $URLList) {
try{
#For proxy systems
[System.Net.WebRequest]::DefaultWebProxy = [System.Net.WebRequest]::GetSystemWebProxy()
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
#Web request
$req = [system.Net.WebRequest]::Create($uri)
$res = $req.GetResponse()
}catch {
#Err handling
$res = $_.Exception.Response
}
$req = $null
#Getting HTTP status code
$int = [int]$res.StatusCode
#Writing on the screen
Write-Host "$int - $uri"
#Disposing response if available
if($res){
$res.Dispose()
}
}
Place a file "URLList.txt" with list of URLs in the same directory "D:\MonitorWeb\"
e.g:
http://www.google.com
http://google.com
http://flexboxfroggy.com
http://www.lazyquestion.com/interview-questions-and-answer/es6
Now open normal command prompt and navigate to the "D:\MonitorWeb\" and type below command:
powershell -executionpolicy bypass -File .\AnyName.ps1
And you'll get output like below:
HTTP STATUS 200 = OK
Note:
This works in power-shell version 2 as well.
Works even if you are behind proxy (uses default proxy settings)

Dharman
- 30,962
- 25
- 85
- 135

Singaramani Thangavel
- 185
- 1
- 1
- 12