
Back in the day when The Chairman was first managing IT, the cost of storage mattered and there was no cloud. It might also matter what kind of storage you were using. Naturally, you wanted the fastest local storage. But you needed to make sure you were getting the best value for your storage dollar. Today’s challenge is based on this bygone scenario. You will most likely never need to use the expected solution. But as with all challenges, The Chairman hopes it will extend and sharpen your PowerShell scripting skills. The challenge is aimed at intermediate level scripters with advanced bonus elements.
Intermediate Goals
The premise of the challenge is to process files within a folder or given path. If the file was last modified X number of days ago, move the file to a new location (back in the day this might have been a NAS device or something with slower and less-expensive storage). Then create a link for the file in the current location. If a user accesses the link, it will open the file from the new location.
You should write a PowerShell function that will achieve this goal. The function should also meet these requirements:
- Let the user specify the source folder or path
- Let the user specify the target folder or path
- Let the user specify the last modified date or number of days
- Include appropriate error handling
You may have to test with local folders and artificially create test files to move and link.
Advanced Goals
If your PowerShell skills are a bit more advanced, once you meet the requirements above, see how many of these bonus elements you can address.
- Support -Whatif
- Accept the source folder or path from the pipeline
- Support optional recursion
- Let the user exclude files by extension
- Create an audit trail
- Run as a background job
Ideally, your function should work cross-platform.
The Chairman looks forward to your solutions. Please use the comments to submit links to your work. Good luck.
Here’s a submission! I look forward to feedback. https://github.com/Frajcir/PowerShellLinking
https://github.com/Frajcir/PowerShellLinking
Hi
I rarely use PowerShell, but I came across your website and decided to write my first function. Can you recommend any books, videos or websites I can read? I want to finish your advanced goals.
I’m also interested to see what you think about the basic function.
Thanks
Start with this page https://jdhitsolutions.com/blog/essential-powershell-resources/
https://github.com/DigitalNotebook/PowerShell/blob/main/General%20Windows/Move-FilesReplaceWithLinks.ps1
Here’s my take on the challenge: https://jdhitsolutions.com/blog/powershell/7921/answering-the-powershell-linking-challenge/