星空网 > 软件开发 > ASP.net

powershell对txt文件的服务器进行ping操作

powershell对txt文件的服务器进行ping操作,txt文件有几百台服务器要进行Ping操作。每行一个

#//*************************************************************#//编辑人:
#//编辑单位:
#//编辑作用:ping#//编制时间:2016.01.05#//*************************************************************$stopWatch = [system.diagnostics.stopwatch]::startNew()#************获取当前脚本执行的目录$Location ="d:\" #$PSScriptRoot#**********************创建以yyyy-MM-dd的日志文件夹$folderName ="ping" #*********************全路径$folderPath = $Location + "\" + $folderName#*********************如果根文件夹不存在。则创建根文件夹If((Test-Path $folderPath) -eq $False) { Write-Host "开始创建文件夹...---------------" -ForegroundColor Green New-Item -path $Location -name $folderName -itemType "directory" Write-Host "创建文件夹完毕...---------------" -ForegroundColor Green}#**************************创建2个文件$pingFileName ="ok.txt"#**************************创建ping通的文件$pingFilePath = $folderPath + "\" + $pingFileName ;If((Test-Path $pingFilePath) -eq $False) { Write-Host "开始创建ping通文件...---------------" -ForegroundColor Green New-Item -path $folderPath -name $pingFileName -itemType "File" Write-Host "创建ping通文件完毕...---------------" -ForegroundColor Green}#**************************创建ping不通的文件$nopingFileName ="no.txt"$nopingFilePath = $folderPath + "\" + $nopingFileName ;If((Test-Path $nopingFilePath) -eq $False) { Write-Host "开始创建ping不通文件...---------------" -ForegroundColor Green New-Item -path $folderPath -name $nopingFileName -itemType "File" Write-Host "创建ping不通文件完毕...---------------" -ForegroundColor Green}#**************读取计算机文件TXT(格式一行一个)$computerObjects = Get-Content c:\DNS.txt#***************得到总的要处理的计算机台数$totalCount = $computerObjects.count;#***************提示信息$sContent = "一共有:" + $totalCount.ToString() +"台服务器需要处理!"Write-Host $sContent -ForegroundColor Green#***************成功的服务器台数[int]$successCount = 0;#***************失败的服务器台数[int]$failCount = 0;ForEach($computerObject in $computerObjects){ try { #******************如果ping得通 if (Test-Connection $computerObject -Count 1 -ea 0 -Quiet) { #*********************ping通信息打印 $pingOK = "ping通" + $computerObject.ToString() Write-Host $pingOK -ForegroundColor Green #*********************写入ping通文件 Add-Content -Path $pingFilePath -Value $computerObject #*********************计数器+1 $successCount = $successCount + 1 } #*******************如果ping不通 else { #*********************ping不通信息打印 $pingNO = "ping不通" + $computerObject.ToString() Write-Host $pingNO -ForegroundColor Red #*********************写入ping不通文件 Add-Content -Path $nopingFilePath -Value $computerObject #*********************计数器+1 $failCount = $failCount + 1 } } catch { #*********************出现错误 $errMsg = "ping"+$computerObject.ToString()+ "过程中出现错误" Write-Host $errMsg -ForegroundColor Blue #*********************写入ping不通文件 Add-Content -Path $nopingFilePath -Value $computerObject #*********************计数器+1 $failCount = $failCount + 1 }}#*************执行完毕$stopWatch.Stop()#****************计算一共花费多少时间$totalseconds = $stopWatch.Elapsed.TotalSeconds#**********************打印出一共花费多少时间$tooltip = "处理完毕,一共花费" + $totalseconds.ToString() +"秒"Write-Host $tooltip -ForegroundColor Red

 




原标题:powershell对txt文件的服务器进行ping操作

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

线上支付:https://www.goluckyvip.com/tag/13372.html
巴黎示威活动:https://www.goluckyvip.com/tag/13373.html
利奇马台风:https://www.goluckyvip.com/tag/13374.html
宁波海事局:https://www.goluckyvip.com/tag/13375.html
物流运输:https://www.goluckyvip.com/tag/13376.html
外贸报关:https://www.goluckyvip.com/tag/13377.html
深圳有没有比较好玩的景点 深圳有没有比较好玩的景点推荐一下:https://www.vstour.cn/a/366175.html
长治婚庆女司仪和主持人:https://www.vstour.cn/a/366176.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流