1

I'm currently in the process of creating a new automated PowerShell script to update our RMM agent software on machines. The PS script is designed as a fall back to the in-built automation.

When creating the parameters of .exe file, it works on a new PowerShell line but fails when invoked through the script.

Running the command as an explicit command from PowerShell works fine. Does not work when invoking with two strings.

My PS Parameters:

param (
    [string] $cust,
    [string] $name,
    [switch] $client,
    [switch] $server,
    [switch] $noprobe,
    [switch] $custom
)

Important Variables:

$NETLOGON = $env:LOGONSERVER
$agentInstall = $NETLOGON+"\NETLOGON\Agent\WindowsAgentSetup.exe"

The command that calls the install:

$agentParams = "/s --% /v"CUSTOMERID=$cust CUSTOMERNAME=$name SERVERPROTOCOL=HTTPS SERVERADDRESS=domain.com SERVERPORT=443""
& $agentInstall $agentParams

It does run the EXE, but nothing happens (like the syntax was wrong). No logs or any output as to why it fails.

If I run the command as the following:

\\SERVER\NETLOGON\Agent\WindowsAgentSetup.exe /s --% /v"CUSTOMERID=100 CUSTOMERNAME=\"Customer One\" SERVERPROTOCOL=HTTPS SERVERADDRESS=domain.com SERVERPORT=443"

No problem at all.

Any advice would be appreciated, but I'm guessing it's a syntax issue. The --% is required to parse it through correctly.

0

2 Answers 2

1

The parameter --% disables parsing entirely, i.e. PowerShell will take the remainder of the commandline and pass it as-is. PowerShell variables after --% will NOT be expanded. Also, you cannot put unescaped double quotes inside a double-quoted string.

Define the parameters as an array, escape the double quotes around the argument of the second parameter with backticks, and splat the parameter list on the command:

$agentParams = '/s', "/v`"CUSTOMERID=$cust CUSTOMERNAME=$name SERVERPROTOCOL=HTTPS SERVERADDRESS=domain.com SERVERPORT=443`""
& $agentInstall @agentParams
Sign up to request clarification or add additional context in comments.

4 Comments

Okay, think I've misunderstood the --% considerably. I'll give this a quick go and get back to you, thanks!
Just tried, but still not working I'm afraid. Same results as before. It calls the executable and then just closes.
Try running it directly in a PowerShell console, if you haven't already. Does that give you any output? Also try without the /s (which presumably does a silent install).
Running as a single command is the same result. /S isn't silent, it just hides the "initialization" screen.
0

Having a little tinker, and thanks to Ansgar Wiechers, I found that using --% works, but once defined as a separate parameter in the array.

So, the working code is now:

$agentParams = '/s', '--%', "/v'"CUSTOMERID=$cust CUSTOMERNAME=$name SERVERPROTOCOL=HTTPS SERVERADDRESS=domain.com SERVERPORT=443'""
& $agentInstall @agentParams

1 Comment

The EXE itself needs the --% by the looks of it, in order to pass this through the parameters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.