I’m not sure where to start with this one so apologies in advance if it seems confused.
I would like to query the contents of a .DAT file (.txt format) for a specific text string. Ideally it needs to return an error level so I can then determine a follow up command if required. I’m not sure this kind of thing is possible?
I’ll give the scenario for more context. I am required to update the connection settings for Juniper VPN clients on End User Devices. I only want to update clients which don’t have a specific text string in the connection file (.DAT file). So I’d like to put together a script which first queries the connection file and then runs a command based on the response of the query.
From the research I’ve already done, this kind of thing only seems to be possible with SQL. I have considered going down the route of comparing one file with another but I think that is too open to false negatives.
Any help would be greatly appreciated.
Update
I've managed to use PowerShell to query the file:
get-content -path 'C:\Program Files\Common Files\Juniper Networks\ConnectionStore\connstore.bak' | where-object {$_ -like '*DR Connection*'}
friendly-name: "DR Connection"
I thought I would post my final script which solved my problem just in case anybody else has come across this issue.
#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."
Thanks