Nov 13, 2011 I am trying to install an executable 'McAfee Agent' framepkg.exe through PowerShell with no luck. I am able to install some custom msi packages I wrote via the Win32Products Classes Install Method. I cannot however install this program. What are some other ways you can use to run an. Well, most importantly does it have a 'silent' option? 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. Aug 09, 2017 Installing Windows PowerShell.; 2 minutes to read; In this article. Windows PowerShell comes installed by default in every Windows, starting with Windows 7 SP1 and Windows Server 2008 R2 SP1. If you are interested in PowerShell 6 and later, you need to install PowerShell Core instead of Windows PowerShell.
Powershell Script to Install Software Remotely: The below powershell command was used for installing the application in your remote system. Before executing this command, you need to make sure that you have a valid network connection between this two system.
You can use PowerShell to run an executable (exe). However, you have to consider a few things.
Timothy Warner
Timothy Warner is a Microsoft Cloud and Datacenter Management Most Valuable Professional (MVP) who is based in Nashville, TN. Check out his Azure and Windows Server video training at Pluralsight, and feel free to reach out to Tim via Twitter.
Latest posts by Timothy Warner (see all)
- Specops Password Auditor v7.2: New features - Thu, Sep 12 2019
- EMCO Ping Monitor Enterprise v7 new features - Tue, Sep 10 2019
- Specops password policy v7.2: New features - Mon, Sep 2 2019
PowerShell and external commands
Many of my Windows systems administrator friends know that they can run commands such as the following successfully from a PowerShell console session:
2 | PSC:>notepad'C:file.txt' |
On the other hand, I’m somewhat surprised at how few of these sysadmins understand why and how PowerShell allows these commands run an exe in the first place. Well, I’m here to teach you both the theory and the practice.
Powershell Silent Install Executable
The basics ^
We can execute programs such as ping and notepad because their enclosing directory paths (C:WindowsSystem32 and C:Windows, respectively) exist in the Windows search path by default. See here:
PowerShell can execute an exe, but you need to be explicit in your instructions.
Let’s add that path to our system search path and try again:
The previous statement works all day long; however, you’ll find that the new environment variable disappears after you close the current PowerShell session! To make a permanent change, we’ll need to tap more directly into the .NET Framework by using the [Environment] type accelerator:
[Environment]::SetEnvironmentVariable('Path',$env:Path+';C:Program Files7-zip',[EnvironmentVariableTarget]::Machine) |
Note that you’ll need to open a new PowerShell session to see the change.
The call operator ^
Sublime Text is my favorite text editor, and I can run the program on my workstation by running the following two lines of PowerShell code:
2 | .subl.exe |
However, the following statement fails:
2 | C:Program FilesSublime Text3subl.exe |
![Powershell Command To Install Exe Powershell Command To Install Exe](/uploads/1/2/4/8/124806348/857154568.png)
PowerShell politely runs executables that exist inside search path directories, as previously discussed. Likewise, if we’re in the target directory already, the “dot slash” (./) notation explicitly instructs PowerShell to treat the file as executable. That’s fine.
The problem in the above example is that PowerShell has no earthly idea that subl.exe is an executable. As far as the PowerShell parser is concerned, we simply defined an anonymous string. What’s cool, though, is that we can use the call operator (&) to notify PowerShell that the target resource is, in fact, executable:
![Command Command](/uploads/1/2/4/8/124806348/400395636.jpg)
Passing arguments - where the fun begins ^
Thus far, you may be thinking, “Tim, you’re not teaching me anything new!” Perhaps you already understood environment variables and even the call operator. Fair enough. But have you ever tried to run an external command in PowerShell that used arguments?
Sure, PowerShell can handle switch parameters and key/value arguments on the most popular network utilities, like so:
2 4 | $host='server01' &$exe-host$host-retry$retry |
That last statement reminds me of Perl. ?
Splatting ^
The last method I want to show you involves splatting. In splatting, we pass a hash table into a command and PowerShell spreads out the hash table contents to be used as parameters. To do this, we first create a hash table that contains our arguments and their values:
2 4 | Host='server01' } |
By the way, a hash table, also called an associative array, is simply a collection of key/value pairs that we can treat as a unit or by its constituent parts.
We finish by running the exe and passing the hash table variable:
This topic contains 8 replies, has 2 voices, and was last updated by
Olaf
1 year, 6 months ago.- 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:
- 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! 😉 - Just to be completely sure – you know that you have to have PSRemoting active on the computer you want to execute this uninstaller, right?
- So it should run this way. I tried it with an example command line in my environment and it worked just as intended.
The topic ‘run exe with parameters’ is closed to new replies.