Hello DEREK CHUA,
Thank you for sharing your script. It is well-structured and functional, but there are a few ways you can simplify it without losing functionality:
- Combine helper functions: Instead of separate
Select-FolderDialogandSelect-FileDialog, you can create one generic dialog function that accepts parameters for type and filter. - Use pipeline operations: For building the mapping table, you can use
ForEach-Objectdirectly withGet-Contentto avoid the explicitforloop. - Inline replacement logic: The
Replace-WordsInNamefunction can be shortened by using-replacewith a regex and a script block, though your current approach is clearer. - Recursive folder processing: You can use
Get-ChildItem -Recursewith-Fileand-Directoryfilters to avoid writing a custom recursive function. - Logging: Instead of multiple
Out-Filecalls, you can collect results in an array and export them once at the end.
These changes can reduce the overall length of the script while keeping it maintainable. If this guidance helps, please click “Accept Answer” so others can benefit too. I’d be happy to provide a shortened sample if you’d like to see it in practice.
Best regards,
QQ.