查询特定字符串的文本文件

时间:2017-06-01 14:09:50

标签: windows scripting juniper-network-connect

我不知道从这个开始的地方如果它看起来很困惑,请提前道歉。

我想查询特定文本字符串的.DAT文件(.txt格式)的内容。理想情况下,它需要返回错误级别,以便我可以根据需要确定后续命令。我不确定这种事情是否可能?

我将给出更多上下文的场景。我需要在最终用户设备上更新Juniper VPN客户端的连接设置。我只想更新连接文件(.DAT文件)中没有特定文本字符串的客户端。所以我想把一个首先查询连接文件的脚本放在一起,然后根据查询的响应运行一个命令。

从我已经完成的研究来看,这种事情似乎只能用SQL来实现。我已经考虑过将一个文件与另一个文件进行比较的路线,但我认为这样做对假阴性是开放的。

非常感谢任何帮助。

更新

我设法使用PowerShell查询文件:

get-content -path 'C:\Program Files\Common Files\Juniper Networks\ConnectionStore\connstore.bak' | where-object {$_ -like '*DR Connection*'}
 friendly-name: "DR Connection"

1 个答案:

答案 0 :(得分:0)

我以为我会发布我的最终脚本来解决我的问题以防万一其他人遇到过这个问题。

#File to search for along with what word to search for
$File = Get-Content "C:\Program Files\Common Files\Juniper Networks\ConnectionStore\connstore.bak" | Where-Object { $_.Contains("remotedr") }

#read-host -Prompt "Proceed?"
#write-host "Contents of var: $file"

#If the $file variable is NULL, then run the .BAT file
If($file -eq $null) {
write-host "Launching BAT file..."
    Start-Process -FilePath 'JuniperConfig.cmd' -Wait
#.BAT file will run until it finishes, then the script will continue
}

#Otherwise, do nothing
Else {
write-host "Do nothing"
}

#write-host
#read-host "Pausing. Press ENTER to continue."

由于

相关问题