Mar 28, 2017

Modifying the content of multiple files in different directories with Powershell

I had the problem to have multiple git repositories checked out from one server.
But now the GIT-Server has moved to a different address and the config file in each
git repository points to the wrong server.

The quick solution would have been, to add the old server into the hosts files with the
IP-Address of the new one.

But the "clean" solution is to update the config file in each repository. On a Linux Box,
a find and sed would have done the job for me.

But I'm now on a Windows Box. I could install the cygwin package or something similar to get
the UNIX-Tools, but I have already Powershell 

To get the files, the simple command is:

Get-ChildItem */.git/config 

To modify the content: 

Get-ChildItem */.git/config | foreach { (Get-Content $_).replace('scm.home.com:8080', 'new-scm.home.com:8082') | Set-Content $_ }


The foreach ( ForEach-Object) loop is taken, to have the Object of each config-File available to
store it again with the "Set-Content $_".