Using netsh on PowerShell fails with error: The parameter is incorrect
Asked Answered
L

2

6

I've been trying to run the following command on PowerShell:

    netsh http add sslcert ipport=0.0.0.0:443 certhash=<some certhash> appid={<random guid>}

The problem is, it returns "The parameter is incorrect" every time. I've check the cert hash number, and the generated guid and they all alright. In fact, I ran the same command in cmd.exe and it worked perfectly, which adds to the frustration.

I want to pass variables as the certhash and appid, which is why I'm using PowerShell.

If anyone can help me understand why it isn't working or if there is something missing for it to work on PowerShell.

Laos answered 15/3, 2012 at 14:52 Comment(0)
L
16

I finally learned what the problem was: although in PowerShell you can execute cmd commands natively, the parsing of the command slightly changes, and in this case it disrupted the interpretation of the appid parameter (those curly brackets!).

To solve it, I just enclosed the brackets ({}) and <random guid> in single quotes, as such,

    netsh http add sslcert ipport=0.0.0.0:443 certhash=<certhash> appid='{<random guid>}'

as opposed to (notice the missing 'quotes'),

    netsh http add sslcert ipport=0.0.0.0:443 certhash=<certhash> appid={<random guid>}

and the command worked perfectly.

For more info on PowerShell parsing, Understanding PowerShell Parsing Modes.

Laos answered 16/3, 2012 at 14:28 Comment(0)
C
0

To add to rae1's answer. This also helps if you are using Invoke-Expression

$command = "netsh http add sslcert ipport=$hostIp`:$port certhash=$thumbprint appid='{$appId}'"
Invoke-Expression $command

Notice that the single quotes inside a double quoted string don't prevent the variable from being substituted.

The downside of this method is that you have to escape the colon inside the string with a backtick

Chandos answered 3/5, 2018 at 14:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.