Question:
I have a series of ps1 files in a directory, all of which have different names. I am trying to run them one after another with Start-Process
and the -Wait
parameter. How does loop through all the files in a directory and run one PowerShell script after another? There are no subfolders, and no files that are not of type ps1.
Here is my start:
1 2 3 4 5 |
$DirectoryList = Get-Content -Path C:\test foreach ($Directory in $DirectoryList) { Start-Process -FilePath powershell.exe -ArgumentList ('"{0}\How To Read Me.ps1" -Path "{1}"' -f $PSScriptRoot, $Directory); } |
Answer:
You could simply use the call operator (&
):
1 2 3 4 |
Get-ChildItem 'C:\test' | ForEach-Object { & $_.FullName } |