如何查看网站/URL列表的状态? (使用Power-Shell脚本) [英] How to check status of list of Websites / URLs? (Using Power-Shell script)

查看:258
本文介绍了如何查看网站/URL列表的状态? (使用Power-Shell脚本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一次获取多个URL的http状态以准备报告.如何使用Powershell来实现它?

I want to take the http status of multiple URL at once to prepare a report. How to acheive it using powershell?

推荐答案

我看到了有关通过Windows计算机监视多个网站的问题.我的朋友想检查他以前手动执行的200个URL的状态.我写了一个Power-Shell脚本来克服这个问题.发布它以使所有用户受益.

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.

将以下代码另存为"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()
    }
}

在同一目录中放置文件"URLList.txt" 和URL列表"D:\ MonitorWeb \"

Place a file "URLList.txt" with list of URLs in the same directory "D:\MonitorWeb\"

例如:

http://www.google.com
http://google.com
http://flexboxfroggy.com
http://www.lazyquestion.com/interview-questions-and-answer/es6

现在打开常规命令提示符,并导航到"D:\ MonitorWeb \" 并在命令下方键入:

Now open normal command prompt and navigate to the "D:\MonitorWeb\" and type below command:

powershell -executionpolicy bypass -File .\AnyName.ps1

powershell -executionpolicy bypass -File .\AnyName.ps1

您将得到如下输出:

HTTP STATUS 200 = OK

注意:

这也适用于Power-shell版本2.

即使您在代理后面(使用默认代理设置)也可以工作

希望这会有所帮助!

这篇关于如何查看网站/URL列表的状态? (使用Power-Shell脚本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆