i need to make a script for "check/replace/add string to the file. The "correct" string is "google.com 44.10.15.9" I have a part of the script for adding the whole line, but i don't know how to make it check other options, If the string would be there but only "google.com" without address or with wrong address. My work looks like this.
$file= 'C:\Users\fialbvoj\Desktop\testPS.txt'
$name=" google.com "
$IP=" 44.10.15.9 "
$line="google.com 44.10.15.9"
$search=(Get-Content $file | Select-String -Pattern 'google.com 44.10.15.9').Matches.Success
if ($search ) {"Success"
} else {
Add-Content -Path $file -Value $line
}
Thank you in advance. Best Regards