$FolderBrowserDialog = New-Object System.Windows.Forms.FolderBrowserDialog if($FolderBrowserDialog.ShowDialog() -eq 'OK'){ $DirName = $FolderBrowserDialog.SelectedPath + "\*" Get-ChildItem $DirName -include *.xml | foreach-object{ $content = Get-Content $_ $newname = "/xx/xxxxxxx/xxx/" + $_.name.SubString(15,4) + ".html" $content -replace "/xx/xx/xx/xx.html", $newname | Set-Content $_ } }