搜索txt文件并返回PC名称(如果存在字符串)

时间:2018-07-27 17:43:18

标签: powershell

我可能不应该添加我要调整的脚本,因为它可能不是开始的最佳选择。我只是知道它必须能够从文本文件中获取字符串并返回一些结果。这基本上是我需要的。想要添加这样的变量:$ env:COMPUTERNAME 每台PC都在C:\ someSoftware \ version \中有一个文件,并且有一个txt文件。

在此文本文件中,有一个版本号,格式如下:VER = 1.425.1

我想让脚本告诉我哪些计算机不是1.425.1版

在此问题上的任何帮助都将不胜感激。

$Path = "C:\Admin\"
$Text = "SomeText"
$PathArray = @()
$Results = "C:\temp\test.txt"

# This code snippet gets all the files in $Path that end in ".txt".

Get-ChildItem $Path -Filter "*.txt" |
Where-Object { $_.Attributes -ne "Directory"} |

ForEach-Object {
  If (Get-Content $_.FullName | Select-String -Pattern $Text) {
    $PathArray += $_.FullName
    $PathArray += $_.FullName
  }
}

Write-Host "Contents of ArrayPath:"
$PathArray | % {$_} | Out-File "C:\SearchString\Output.txt"

0 个答案:

没有答案
相关问题