I'm trying to replace a hostname with an FQDN located anywhere in a specific file. The following works fine, unless the FQDN is already in the file. If FQDN is there, it adds a second domain name to the FQDN.
$test = Get-Content C:\temp\test.txt
$test -replace ($compname, $fqdn)
Essentially, I need to replace if, and only if, the string matches compname, but doesn't match FQDN.
Any suggestions? Thanks!
$compname, $fqdn