String Replace in text file with Powershell

19 June,2013 by Jack Vamvas

How can I replace a string  in a text file using Powershell?


To replace a string in Powershell use the Get_Content cmdlet  and –replace function.

This example , sources the file “ssis.txt”   and   replaces 'package_somedate’ with 'package_20130619' . Easy.



$src_file = 'c:\ssis.txt' (Get-Content $src_file) | Foreach-Object { $_ -replace 'package_somedate$', 'package_20130619' ` } | Set-Content $src_file

 Read More

Compare two files with Powershell - SQL Server DBA

SQL Database Size report using Powershell - SQL Server DBA

List failed SQL server Jobs with Powershell - SQL Server DBA

Author: Jack Vamvas (


Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.


Post a comment on String Replace in text file with Powershell | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer