Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to get the file names in a directory which are exe and then execute them one by one:

$files = get-childitem mydirectory

foreach ($file in $files)
{
     $file /s
}

But somehow the powershell is not liking this - it is complaining about the "/s". The $file contains valid file name which I checked against Write-Host. Now how to resolve this problem.

Thanks

share|improve this question
add comment

1 Answer 1

Seems you have missed the call operator &

$files = get-childitem -Filter *.exe folder
foreach ($file in $files)
{
     &$file.Fullname /s
}

But you can also use start-process

$files = get-childitem -Filter *.exe folder
foreach ($file in $files)
{
     Start-Process $file.Fullname -ArgumentList "/s"
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.