Hi, I am running the script below to rename files and it is working fine. what I would like to add is something that would either show in PS or export in a CSV file all the changes made.
For example, if I am renaming t+est.pdf to test.pdf, the output I need something that says
old name t+est.pdf new name test.pdf.
Set-Location -Path “C:\Temp\File rename”
Get-ChildItem -Recurse -Include *.pdf | Rename-Item -NewName {$.Name.Replace(“+”,"")}
Thank You
You could start with something like this:
Get-ChildItem -Path “C:\Temp\File rename” -Recurse -Include *.pdf |… untested!!
ForEach-Object{
[PSCustomObject]@{
NameBefore = $.Name
NameAfter = $.Name.Replace(“+”,“")
}
Rename-Item -Path $.FullName -NewName {$.Name.Replace(“+”,"”)}
}
Of course you could pipe the output to whatever further cmdlet or file you want.
You can use Write-Output to print it in the console or if in a CSV you can build a PSCustomObject with Oldname and Newname as headers and export it to a CSV. Yourself can do it, there are lot of example in the web on PSCustomObjects. Once you face any issues using CustomObjects, update it here, we will guide you.
here is a link for understanding PScustomObjects : Powershell: Everything you wanted to know about PSCustomObject
If you are very new to PowerShell, I would suggest you to take some time in learning and understanding the language else you will get frustrated by doing things not right.
A good places to start
<li>MVA - https://mva.microsoft.com/en-us/training-courses/getting-started-with-powershell-3-0-jump-
start-8276
<li>PowerShell in a month of lunches - https://www.manning.com/books/learn-windows-powershell-in-a-month-of-lunches-second-edition</li></ul>
rename-item has -verbose and -passthru options. But passthru only returns in the new file.