hi, im new to powershell, but i wanna create a program that can replace a string with what a user will input within multiple different files.
this is my code:
$NewString = Read-Host -Prompt 'Input New Name Please' $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition $InputFiles = Get-Item "$scriptPath\*.md" $OldString = 'SolutionName' $InputFiles | ForEach { (Get-Content -Path $_.FullName).Replace($OldString,$NewString) | Set-Content -Path $_.FullName } echo 'Complete'
but it will only change a certain file, how do i make it look through all files in the folder it is in, and change the oldstring with the newstring ?
EDIT:
This was my solution
# Path of the current folder $path = split-path -parent $MyInvocation.MyCommand.Definition #input from user, to replace with. $NewString = Read-Host -Prompt 'Input New Name Please' #What to replace $OldString = '%SolutionName%' #find all items, go through them and make the changes. Get-ChildItem -Path $path | where {!$_.PsIsContainer} | foreach { (Get-Content $_).Replace($OldString,$NewString) | Set-Content -Path $_.FullName } echo 'Action is complete '