Tip: You have a list of files with a specific prefix and you want to rename that.
For example, here you want to fix a wrong name WORSTATION to WORKSTATION.
1 2 3 4 |
#requires -Version 1 Get-ChildItem -Path 'C:\Demo\Logs' | ForEach-Object -Process { Rename-Item -Path $_.Name -NewName ($_.Name.Insert(3,'K')) } |
Parameter 1 : the start index (the position)
Parameter 2 : the string to insert
String.Insert Method (Int32, String)
https://msdn.microsoft.com/en-us/library/system.string.insert(v=vs.110).aspx