Massive Replace text in files Source Control TFS using Powershell

I have many connectionstrings in *.config files in all C: drive. I use Windows 8, VS 2012, TFS 2008.

I have some *.config files in Source Control TFS, with workspace mapped in local folder C:\TFS.

I have some *.config files out Source Control TFS, in another folders (C:\Tests, C:\Windows, C:\Temp, etc).

I want replace password in all *.config files.

Maybe better using scripting like Powershell or bat/cmd files.

 <add name="ConnectionStrings.Oracle.ConnectionLog" connectionString="DATA SOURCE=xxx;PASSWORD=AAAAAAA;PERSIST SECURITY INFO=True;USER ID=MYUSER"
  providerName="Oracle.DataAccess.Client" />

I use

var configs = Directory.GetFiles(@"C:\", "*.config");

configs.ForEach( f => ReplacePasswordOfFile(f));

If *.config file is out TFS, I want:

If *.config file is in TFS, I want:

How can I know if a config file is or not in Source Control TFS ? Any suggestions about this process?

Upvotes: 0

Views: 802

Answers (1)

xcodr
xcodr

Reputation: 1177

This will loop over all files in a specific branch and output the name. This will give you a list of config files in TFS.

$serverBranchLocation = "$/Project/Branch" 
$tfs=Get-TfsServer -name http://tfs:8080/tfs

foreach ($item in Get-TfsChildItem $serverBranchLocation -recurse -server $tfs)  { 
    if ($item -match "*.config") {
        echo $item
    } 
}

Upvotes: 0

Related Questions