Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .