2

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

1 Answer 1

7

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"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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