PowerShell Ping the TXT file server

Source: Internet
Author: User

PowerShell Ping the TXT file server, the TXT file has hundreds of servers to ping. One per line

#//*************************************************************#//Editor:
#//Edit unit:
#//Edit role: Ping#//Preparation time: 2016.01.05#//*************************************************************$stopWatch= [System.diagnostics.stopwatch]::StartNew ()#************ Get the current script execution directory$Location="D:\" #$PSScriptRoot#********************** Creating a log folder with Yyyy-mm-dd$folderName="Ping" #********************* Full path$folderPath=$Location+"\"+$folderName#********************* If the root folder does not exist. The root folder is createdIf((Test-path$folderPath)-eq $False) {Write-host"Start Creating folder ...---------------"-Foregroundcolor Green New-item-path$Location-name$folderName-itemtype"Directory"Write-host"Create folder complete ...---------------"-Foregroundcolor Green}#************************** creation of 2 files$pingFileName="Ok.txt"#************************** Creating a ping pass file$pingFilePath=$folderPath+"\"+$pingFileName ;If((Test-path$pingFilePath)-eq $False) {Write-host"start creating a ping Pass file ...---------------"-Foregroundcolor Green New-item-path$folderPath-name$pingFileName-itemtype"File"Write-host"Create ping Pass file complete ...---------------"-Foregroundcolor Green}#************************** Creating a file that is not ping$nopingFileName="No.txt"$nopingFilePath=$folderPath+"\"+$nopingFileName ;If((Test-path$nopingFilePath)-eq $False) {Write-host"Start creating ping non-pass file ...---------------"-Foregroundcolor Green New-item-path$folderPath-name$nopingFileName-itemtype"File"Write-host"Create ping not pass file complete ...---------------"-Foregroundcolor Green}#************** Read the computer file txt (one line in a format)$computerObjects= get-Content c:\DNS.txt#*************** Get the total number of computers to be processed$totalCount=$computerObjects. Count;#*************** Tip Information$sContent="altogether there are:"+$totalCount. ToString () +"server needs to be processed! "Write-host$sContent-Foregroundcolor Green#*************** number of successful server stations[INT]$successCount= 0;#*************** number of failed server tables[INT]$failCount= 0;ForEach($computerObject inch $computerObjects) {try {#****************** If the ping is to pass if(test-connection$computerObject-count 1-ea 0-Quiet) { #*********************ping Pass Information printing $pingOK="Ping Pass"+$computerObject. ToString () Write-host$pingOK-Foregroundcolor Green#********************* writing to a ping pass fileAdd-content-path$pingFilePath-value$computerObject #********************* counter +1 $successCount=$successCount+ 1 } #******************* If the ping does not pass Else { #*********************ping Non-pass information printing $pingNO="Ping does not pass"+$computerObject. ToString () Write-host$pingNO-Foregroundcolor Red#********************* Write ping non-pass fileAdd-content-path$nopingFilePath-value$computerObject #********************* counter +1 $failCount=$failCount+ 1}} catch {#********************* Error occurred $ERRMSG="Ping"+$computerObject. ToString () +"An error occurred during the process"Write-host$ERRMSG-Foregroundcolor Blue#********************* Write ping non-pass fileAdd-content-path$nopingFilePath-value$computerObject #********************* counter +1 $failCount=$failCount+ 1 }}#************* Execution Complete$stopWatch. Stop ()#**************** Calculate how much time it takes$totalseconds=$stopWatch. Elapsed.totalseconds#********************** How much time it takes to print out$tooltip="after processing, it costs"+$totalseconds. ToString () +"seconds"Write-host$tooltip-foregroundcolor Red

PowerShell Ping the TXT file server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.