C Hutch
C Hutch

Reputation: 3

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?

Upvotes: 0

Views: 390

Answers (1)

Garrett
Garrett

Reputation: 649

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

Upvotes: 2

Related Questions