PowerShell function to replace a string in a given text file

0
function Replace-StringInFile {

    param(
        [System.String]$file,
        [System.String]$searchString,
        [System.String]$replaceString
    )

    [System.IO.File]::WriteAllText($file, [System.IO.File]::ReadAllText($file).Replace($searchString, $replaceString))
    
}

Function usage:

Replace-StringInFile -file "C:\input.csv" -searchString "http" -replaceString "https"
Share.

About Author

Christian Unnerstall

Christian Unnerstall, founder of devshooin.com, enjoys designing and building things that look nice and work well, whether it's websites or services within the interwebs. Have questions - feel free to reach out to him. Enjoy

Leave a Reply