QuickTip – PowerShell – Run External Commands with Variables
If you want to be able to run commands for an external application in a PowerShell script with defined variables, you can use the following method. In my case, I wanted to trigger some PDQ Deploy packages to install on a certain computer (as part of larger initial deployment script), where the computer name is set using a variable. Here is an example of three lines that will allow you to run PDQDeploy.exe with its own parameters, mixed with a variable set in PowerShell.
$Computer = "TestPC-01" $PDQDeployEXE = "C:\Program Files (x86)\Admin Arsenal\PDQ Deploy\PDQDeploy.exe" &$PDQDeployEXE Deploy -Package "Dell-Laptops-Newly-Imaged" -Target $Computer
First, you define the variable with the path to PDQDeploy.exe. Next, you precede the command(s) you want to run with the “&” sign, followed by the variable for the PDQDeploy executable (defined in the first step) with the parameters necessary to make the command run.
In the above example, the target computer is manually specified using the $Computer variable. However, there are many ways to get or set the computer name to define this variable.