This feels like it should be straightforward, however, I am coming a bit undone. I want to replace text in a file so that people's VPN configs point to a new address. As each config file is the user's name I first go to the uniform VPN path in windows, then find the VPN config file. From here it should just be a case of getting that content and then replacing it. So my thinking was to get a path variable which will go to the OpenVPN config folder. From there find where the .ovpn file is kept and get the name of that file. String replace the text in that file and overwrite said file. I have managed to successfully do this with manually entering my own file / config paths, I just want to automate it for the staff we have otherwise that's a lot of manual edits I need to do.
I'm aware that this will also need to be ran as admin.
This is what I have currently got.
$path="C:\Program Files\OpenVPN\config\"
$ConfigFile = Get-ChildItem -Path $path -Recurse -Filter "*.ovpn" | select name
(Get-Content $ConfigFile) -replace 'x.x.x.x', 'y.y.y.y' | Set-Content $ConfigFile
select nameand do:(Get-Content $ConfigFile.FullName) -replace 'x.x.x.x', 'y.y.y.y'Set-Content $ConfigFile.fullname