Rename a bunch of files/directories

This has been quite useful to me as well. Files:get-childitem “*.xml” | foreach { rename-item $_ $_.name.Replace(“NES-“, “NES-X”) }Replace Directories:Get-ChildItem -path PROD -Directory | ForEach-Object -Process {Rename-item -path $_.Name -NewName ($_.name.substring(4,8)) -Verbose }Another example:Get-ChildItem ‘C:\Temp\crs\documents’ | rename-item -newname { $_.name.substring(0,45) + ‘_Client_Report.pdf’} Here is a variant to add a string to an existing file name:get-childitem…

Replace a string inside a list of files

Sometimes we need to replace a character string in a flat file.One possible method could be to use a tool, like notepad++, and open the set of files and use the scan replace options.But a quick way is again using PowerShell as below: ls “\cb.n.lo\dfs\reg01\interfaces\T24\From\523.Asn\LU0010001\DOC\NES-TEST\*.xml” -rec | %{ $f=$_; (gc $f.PSPath) | %{ $_ -replace…