run exe with parameters

This topic contains 8 replies, has 2 voices, and was last updated by  Olaf Soyk 2 months ago.

  • Author
    Posts
  • #96585

    John Curtiss
    Participant

    my end game is to wrap this in invoke-command, to feed a list of PCs, and run the exe on all of them. for now, i'm just trying to run an exe with parameters from powershell. I can run it from a command line and from a scheduled task. but not from powershell. the argument list has a bunch of quotes and backslashes in it.

    the following works from a command prompt:
    c:\scripts>ARMACleanup.exe /S /V"UI=\"Silent\" /l*v \"c:\Windows\logs\ARMACleanup.LOG\""

    the scheduled task "start a program" c:\scripts\armacleanup.exe with arguments:

    /S /V"UI=\"Auto\" /l*v \"c:\Windows\logs\ARMACleanup.LOG\""

    but I can't get it to run in powershell. I have tried saving the argument string as a variable and then various ways of running the exe with the variable.

    set-location c:\scripts
    $silent = '/S /V"UI=\"Auto\" /l*v \"c:\Windows\logs\ARMACleanup.LOG\""' #wrapping it in single quotes
    .\armacleanup.exe $silent
    # or
    # & armacleanup.exe $silent
    # or not setting the location and
    # & c:\scripts\armacleanup.exe $silent

    i get no errors, but nothing happens. the log file doesn't appear in c:\windows\logs, and the software that armacleanup.exe is supposed to uninstall remains uninstalled.

  • #96594

    Olaf Soyk
    Participant

    Looks like a capsuled msi installer to me. Maybe you'd be better off when you extract the msi. This way you would have more control about the installation. But I think this should work actually:

    .\armacleanup.exe '/S /V"UI=Auto /l*v c:\Windows\logs\ARMACleanup.LOG"' 
  • #96648

    John Curtiss
    Participant

    thanks Olaf. you're right, but I don't have the MSI. this is an uninstall tool that was provided to me by my parent company to uninstall some other software that was provided to me by my parent company. if I run the tool from the command prompt, I do see something pop up in the taskbar, but everything goes away with no input from me. that's the "silent" switch. if I run it with the Auto switch, I get prompted for input.

    having said that, your suggestion works IF I take the single quotes off.

    now. back to my end game of running this remotely. when I use invoke-command, the commands on the target are run as Local System, right? is there a way to change that? i'm guessing this encapsulated MSI requires a user session to run, which isn't great for running as Local System. can I put credentials inside an invoke-command scriptblock to be used on the remote computer? I don't even care if they are plain text. i'm running this myself, one time.

  • #96656

    Olaf Soyk
    Participant

    John,
    as you can see in the help for Invoke-Command it supports the parameter -Credential. So you can provide whatever account you like. But of course it has to one with administratove access to the target computer. The command executes on the remote computer as the user account you specified or if you did not specify as your account if you have administrative access.
    Before you procedd you should carefully review the complete help for Invoke-Command including all of the examples.
    Regardless of that – usually it is possible to extract the msi from the setup executable. Google it and probably you will find something. Even if not – if it's an installaed msi package you wouldn't even need and uninstall programm. You just need the product guid and you can uninstall it with "msiexec.exe /X{}".
    Good luck! 😉

  • #96657

    John Curtiss
    Participant

    i'm running the script on my workstation as john.curtiss, which is an admin on RemoteServer, and has NTFS and Share Full Control of \\server\share\folder.

    invoke-command RemoteServer -scriptblock {set-location \\server\share\folder}

    gives me access denied on the set-location action. how is this possible if set-location is being run as john.curtiss, who has NTFS and Share Full Control of \\server\share\folder?

    john.curtiss can set-location in my local ISE:

    PS C:\Users\john.curtiss> set-location \\sisfpsp5\techservices$
    PS Microsoft.PowerShell.Core\FileSystem::\\sisfpsp5\techservices$>

    but john.curtiss gets access denied if he tries to set-location remotely:

    PS C:\Users\john.curtiss> Invoke-Command sismovp1 {set-location \\sisfpsp5\techservices$}
    Access is denied
    + CategoryInfo : PermissionDenied: (\\sisfpsp5\techservices$:String) [Set-Location], UnauthorizedAccessException
    + FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.SetLocationCommand
    + PSComputerName : sismovp1

    Cannot find path '\\sisfpsp5\techservices$' because it does not exist.
    + CategoryInfo : ObjectNotFound: (\\sisfpsp5\techservices$:String) [Set-Location], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
    + PSComputerName : sismovp1

    • #96663

      John Curtiss
      Participant

      nevermind. I see that set-location to a UNC path is a "second hop" issue.

      unfortunately the software that armacleanup cleans up was purposely installed in a way that even an administrator can't just right-click, uninstall from control panel. there is some security around it. this armacleanup.exe works around that security. I have to run this exe.

      ok. so if john.curtiss is an admin on sismovu1, I don't need to specify credentials when using invoke-command to sismovu1.

      and john.curtiss runs

      invoke-command sismovu1 -scriptblock {
      Set-Location C:\scripts
      .\armacleanup.exe /S /V"UI=Silent /l*v c:\Windows\logs\ARMACleanup.LOG"
      }

      nothing is happening.

      but if john.curtiss RDPs to sismovu1 and runs

      Set-Location C:\scripts
      .\armacleanup.exe /S /V"UI=Silent /l*v c:\Windows\logs\ARMACleanup.LOG"

      the exe runs and does its job.

  • #96741

    Olaf Soyk
    Participant

    Just to be completely sure – you know that you have to have PSRemoting active on the computer you want to execute this uninstaller, right?

  • #96764

    John Curtiss
    Participant

    Of course. Wouldn't invoke-command throw an error if it wasn't?

  • #96879

    Olaf Soyk
    Participant

    So it should run this way. I tried it with an example command line in my environment and it worked just as intended.

You must be logged in to reply to this topic.