-1

我不确定从哪里开始,所以如果看起来很困惑,请提前道歉。

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

我将给出更多上下文的场景。我需要更新最终用户设备上瞻博网络 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"
4

1 回答 1

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."

谢谢

于 2017-06-02T14:02:57.967 回答