国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 漯河市| 台中县| 德钦县| 牙克石市| 威远县| 普格县| 西乌珠穆沁旗| 泌阳县| 普兰店市| 建瓯市| 额敏县| 姚安县| 香河县| 兰考县| 长汀县| 鸡泽县| 新闻| 昌都县| 仙桃市| 广安市| 临朐县| 合水县| 莆田市| 习水县| 白城市| 台山市| 错那县| 东至县| 竹溪县| 陇西县| 大竹县| 永丰县| 凭祥市| 张家界市| 长沙市| 凌海市| 九江市| 思茅市| 吉木萨尔县| 哈密市| 莱州市|