Basic Find Replace Script

I'm looking for some documentation that would pretty much tell me how to find a line in a file (hostname=server_1) and replace it with the actual host name of where the file resides.  I plan on running this against 5,000+ servers; we want to use the FQDN and not the short name.  Will any of the books point me in the correct direction and if so, which one's?  We have an environment of Windows 2003, 2008, and 2012 servers.

Thanks everyone/anyone.

August 19th, 2015 4:21pm

Hi,

Here's something you can play with:

(Get-Content .\config.txt).Replace('(hostname=server_1)',"(hostname={0})" -f "$($env:COMPUTERNAME).$($env:USERDNSDOMAIN)")|
    Set-Content .\config.txt


config.txt before script is run:
blah1
blah2
(hostname=server_1)
blah3

config.txt after script is run:
blah1
blah2
(hostname=hostname.domain.com)
blah3

This only works if you run it locally.

Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 4:31pm

Thanks!!!  That's nice of you.  We'll mess around with this and I'll also need to find something with WMI because not all of our servers have Powershell.  Ughhhh...  Thanks again.
August 19th, 2015 6:33pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics