How to search multiple folders in a directory for .ps1 files
Clash Royale CLAN TAG#URR8PPP
How to search multiple folders in a directory for .ps1 files
I'm currently trying to streamline the installation process of a few products that require a powershell script to be run each, I've encountered some trouble when trying to write a script to search a directory for these files.
Example: in the directory 'Install' i have four subfolders named 'product1-4' in each of these folders there is a file 'Script.ps1'
The first issue is that the install scripts are all named the same 'script.ps1' which complicated my first idea to pull all the files from the sub-folders into a centralised location and run them all sequentially.
Feel like i'm making this more complicated than it needs to be, any advice?
1 Answer
1
Get-ChildItem $installFolder -Include *.ps1 -Recurse
That will list the .ps1 files, you could also do the following to then address the files as a single variable.
$ps1Files = Get-ChildItem $installFolder -Include *.ps1 -Recurse
Remind me what the purpose of the text file is
– Garrett
Aug 8 at 15:39
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thank you, that works a treat! When using this method is it still worth passing the results through to a text file and using that to run them all?
– C Hutch
Aug 8 at 8:29