2015-04-22 117 views
0

我有一個簡單的Powershell腳本來檢查網絡計算機上BitLocker驅動器加密的狀態。我希望腳本能夠確定文本文件中多臺計算機的狀態。從文本文件中讀取計算機名稱並執行命令

這裏是到目前爲止我的基本腳本:

$GetID = Read-Host "What is the Device ID?" 
$ComputerID = manage-bde -status -cn "$GetID" 
foreach ($Computer in $ComputerID) { 
    Write-Host("$Computer") 
} 

這樣做是提示輸入主機名的高科技,並給出了結果。我該如何讓腳本提示技術人員獲取文本文件的路徑,然後讓腳本提供該文本文件的結果列表?

回答

0
$TextFilePath = Read-Host "What is the path to the text file?" 
If (Test-Path $TextFilePath){ 
    $ComputersArray = Get-Content $TextFilePath 
    ForEach ($Computer in $ComputersArray) { 
     If (Test-Connection $Computer -Count 1){ 
      $ComputerStatus = manage-bde -status -cn "$Computer" 
      Write-Host($ComputerStatus) 
     } Else { 
      Write-Host("$Computer appears to be offline.") 
     } 
    } 
} Else { 
    Write-Error "The text file was not found, check the path." 
} 
+0

謝謝你,工作。現在我試圖將數據輸出到一個txt文件,並且它部分工作,但是,它只是從計算機列表中的第一個條目寫入第一個結果。編輯:嘗試添加代碼 – James

+0

'$ TextFilePath = Read-Host「文本文件的路徑是什麼?」 如果(測試的路徑$ TextFilePath){$ = ComputersArray獲取內容$ TextFilePath 的ForEach($ Computer於$ ComputersArray){ 如果(測試連接$計算機-Count 1){$ =計算機狀態管理-BDE - 狀態-cn「$計算機」|出文件-FilePath 「C:\用戶\ isjko1 \ BitLocker的status.txt中」 }其他{ 寫主機( 「$電腦顯示爲脫機狀態。」) }} } 否則{ 寫入錯誤「文本文件沒有找到,請檢查路徑。」 }' – James

+0

問另一個問題 –

相關問題