国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

powershell對txt文件的服務器進行ping操作

2019-11-14 13:33:40
字體:
來源:轉載
供稿:網(wǎng)友

powershell對txt文件的服務器進行ping操作,txt文件有幾百臺服務器要進行Ping操作。每行一個

#//*************************************************************#//編輯人:
#//編輯單位:
#//編輯作用:ping#//編制時間:2016.01.05#//*************************************************************$stopWatch = [system.diagnostics.stopwatch]::startNew()#************獲取當前腳本執(zhí)行的目錄$Location ="d:/" #$PSScriptRoot#**********************創(chuàng)建以yyyy-MM-dd的日志文件夾$folderName ="ping" #*********************全路徑$folderPath = $Location + "/" + $folderName#*********************如果根文件夾不存在。則創(chuàng)建根文件夾If((Test-Path $folderPath) -eq $False) { Write-Host "開始創(chuàng)建文件夾...---------------" -ForegroundColor Green New-Item -path $Location -name $folderName -itemType "directory" Write-Host "創(chuàng)建文件夾完畢...---------------" -ForegroundColor Green}#**************************創(chuàng)建2個文件$pingFileName ="ok.txt"#**************************創(chuàng)建ping通的文件$pingFilePath = $folderPath + "/" + $pingFileName ;If((Test-Path $pingFilePath) -eq $False) { Write-Host "開始創(chuàng)建ping通文件...---------------" -ForegroundColor Green New-Item -path $folderPath -name $pingFileName -itemType "File" Write-Host "創(chuàng)建ping通文件完畢...---------------" -ForegroundColor Green}#**************************創(chuàng)建ping不通的文件$nopingFileName ="no.txt"$nopingFilePath = $folderPath + "/" + $nopingFileName ;If((Test-Path $nopingFilePath) -eq $False) { Write-Host "開始創(chuàng)建ping不通文件...---------------" -ForegroundColor Green New-Item -path $folderPath -name $nopingFileName -itemType "File" Write-Host "創(chuàng)建ping不通文件完畢...---------------" -ForegroundColor Green}#**************讀取計算機文件TXT(格式一行一個)$computerObjects = Get-Content c:/DNS.txt#***************得到總的要處理的計算機臺數(shù)$totalCount = $computerObjects.count;#***************提示信息$sContent = "一共有:" + $totalCount.ToString() +"臺服務器需要處理!"Write-Host $sContent -ForegroundColor Green#***************成功的服務器臺數(shù)[int]$successCount = 0;#***************失敗的服務器臺數(shù)[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 #*********************計數(shù)器+1 $successCount = $successCount + 1 } #*******************如果ping不通 else { #*********************ping不通信息打印 $pingNO = "ping不通" + $computerObject.ToString() Write-Host $pingNO -ForegroundColor Red #*********************寫入ping不通文件 Add-Content -Path $nopingFilePath -Value $computerObject #*********************計數(shù)器+1 $failCount = $failCount + 1 } } catch { #*********************出現(xiàn)錯誤 $errMsg = "ping"+$computerObject.ToString()+ "過程中出現(xiàn)錯誤" Write-Host $errMsg -ForegroundColor Blue #*********************寫入ping不通文件 Add-Content -Path $nopingFilePath -Value $computerObject #*********************計數(shù)器+1 $failCount = $failCount + 1 }}#*************執(zhí)行完畢$stopWatch.Stop()#****************計算一共花費多少時間$totalseconds = $stopWatch.Elapsed.TotalSeconds#**********************打印出一共花費多少時間$tooltip = "處理完畢,一共花費" + $totalseconds.ToString() +""Write-Host $tooltip -ForegroundColor Red

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 贡山| 罗山县| 中阳县| 旌德县| 磐石市| 阳原县| 西和县| 贵南县| 太仆寺旗| 凌海市| 普安县| 绍兴县| 民权县| 镇康县| 涿州市| 大洼县| 安远县| 拉萨市| 镇赉县| 纳雍县| 梅州市| 乐业县| 古交市| 昂仁县| 遂宁市| 香格里拉县| 手游| 马关县| 仲巴县| 道真| 甘南县| 上犹县| 嵊州市| 平度市| 曲阜市| 甘洛县| 梧州市| 昌平区| 和平县| 石门县| 疏勒县|