2015-04-22 125 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

问另一个问题 –

相关问题