locked
Trying to install a program with powershell in multiple folders with a argument RRS feed

  • Question

  • Hey Guys

    Maybe i have more luck with help here. Im trying to install a .exe with an argument that is located in many folders under one path.

    Im trying this one but failing abit on the argument after the .exe file.

    Get-Childitem -path "C:\test1\test" -Recurse -Filter "executable_x64.exe" | foreach-object {
      start-process $ENV:SystemRoot\system32\cmd.exe -argumentlist ('/c "' + ("$($_.FullName)." + '--install') + '"' )
    }

    If i rchange it to this it will execute the file but i can't install it.

    Get-Childitem -path "C:\test1\test" -Recurse -Filter "executable_x64.exe" | foreach-object {
      start-process $ENV:SystemRoot\system32\cmd.exe -argumentlist ('/c "' + $_.FullName + '"' )
    }

    Im hoping someone here can help out.

    JT

    Thursday, August 31, 2017 2:39 PM

All replies

  • Hi Jan-Tore,

    Is there a reason you cannot call the exe directly? 

    Get-Childitem -Path "C:\test1\test" -Recurse -Filter "executable_x64.exe" | ForEach-Object {
      Start-Process -FilePath $_.FullName -ArgumentList '--install'
    }
    

    Liam

    Thursday, August 31, 2017 2:43 PM
  • Why are you using Get-ChildItem -recurse?  Just use the file name

    Start-Process -FilePath C:\test1\test\executable_x64.exe -ArgumentList '--install'

    Your construct is only useful if their are multiple files.


    \_(ツ)_/

    Thursday, August 31, 2017 4:31 PM
  • There is multiple folders with the same executable inside.

    I have tried multiple scenarios

    Start-Process -FilePath C:\test\test1\service_x64.exe  -ArgumentList '--install'

    And so on, it just does not work. The correct way to install is service_x64.exe --install with --install as the correct option to install it. This is a inhouse developed service, wich i need to install about 30 off on about 30 servers. So the option to do this manualy is a pain :( I got most of the script done, except for getting it installed, and editing the config file with the script.

    JT

    Thursday, August 31, 2017 7:12 PM
  • Get-ChildItem C:\test1\test\executable_x64.exe -Recurse |
    	ForEach-Object{
    		Start-Process -FilePath $_.FullPath -ArgumentList '--install'
    	}
    


    \_(ツ)_/

    Thursday, August 31, 2017 8:02 PM
  • Im not getting this to work.

    I just see a blip on my screen and it goes away.

    Get-ChildItem C:\test1\test\executable_x64.exe -Recurse |
    	ForEach-Object{
    		Start-Process -FilePath $_.FullPath -ArgumentList '--install'
    	}

    Friday, September 1, 2017 8:35 AM
  • Start-Process -FilePath$_.FullPath -ArgumentList '--install' -NoNewWindow
     

    \_(ツ)_/

    Friday, September 1, 2017 9:06 AM
  • We figured out what the issue is. Just need to fix it.

    The program requires the config file to install. Normaly when you run it with --install it finds the config file where the program is located.

    But as it runs from a diffrent folder, with the path inside the script, we need to add the path of the config file in the arguments.

    So it should be --install --config c:\test\program$\config.xml

    But we need to find a way to add the folder name as it changes.

    Saturday, September 2, 2017 2:11 PM
  • So the fix was quite easy. As the program runs with a path. But it looks for the config file from the wrong path if you  run it from like c:\

    so needed to add the config file into the arguments list.

    Start-Process -FilePath  program_x64.exe -ArgumentList "--config=config.xml --install"

    JT

    Friday, September 8, 2017 8:26 AM
  • Hi,

    Was your issue resolved? 

    And if the replies as above are helpful, we would appreciate you to mark them as answers, and if you resolve it using your own solution, please share your experience and solution here and "mark it as answer" to help other community members find the helpful reply quickly.. It will be greatly helpful to others who have the same question.

    Best Regards,
    Albert Ling

    Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Wednesday, September 13, 2017 7:25 AM