Error while using "add ssl cert" netsh command in powershell

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 6 months ago.

  • Author
    Posts
  • #5341

    by pankaj.nagrale at 2012-12-11 23:04:16

    I am getting below error for "add ssl cert" netsh command. I am using this command from my powershell script. The command is working fine on windows command promt. Is it that powershell doesn't support nestsh commands?

    PS C:\Pankaj\BranchCache> netsh
    netsh>http
    netsh http>netsh http add sslcert ipport=0.0.0.0:443 certhash=DB76AF93AAB3E202A5C4EA5DE5E2E3704816623A appid={d673f5ee-a714-454d-8de2-492e4c1bd8f8}
    The following command was not found: netsh http add sslcert ipport=0.0.0.0:443 certhash=DB76AF93AAB3E202A5C4EA5DE5E2E3704816623A appid={d673f5ee-a714-454d-8de2-492e4c1bd8f8}.

    netsh http>exit

    PS C:\Pankaj\BranchCache> netsh http add sslcert ipport=0.0.0.0:443 certhash=DB76AF93AAB3E202A5C4EA5DE5E2E3704816623A appid={d673f5ee-a714-454d-8de2-492e4c1bd8f8}
    The parameter is incorrect.

    by nohandle at 2012-12-12 02:25:40

    [quote="pankaj.nagrale"]PS C:\Pankaj\BranchCache> netsh
    netsh>http
    netsh http>netsh http add sslcert ipport=0.0.0.0:443 certhash=DB76AF93AAB3E202A5C4EA5DE5E2E3704816623A appid={d673f5ee-a714-454d-8de2-492e4c1bd8f8}[/quote]
    you already are in the netsh http context you should call only the 'add sslcert ipport=0.0.0.0:443 certhash=DB76A...'

    by nohandle at 2012-12-12 02:41:19

    [quote="pankaj.nagrale"]PS C:\Pankaj\BranchCache> netsh http add sslcert ipport=0.0.0.0:443 certhash=DB76AF93AAB3E202A5C4EA5DE5E2E3704816623A appid={d673f5ee-a714-454d-8de2-492e4c1bd8f8}
    The parameter is incorrect.[/quote]
    I get another error but I managet it to work. You have to enclose every paremeter to apostrophes and pass the whole string to invoke-expression.
    $original ='netsh http add sslcert ipport=0.0.0.0:443 certhash=DB76AF93AAB3E202A5C4EA5DE5E2E3704816623A appid={d673f5ee-a714-454d-8de2-492e4c1bd8f8}'
    $command,$arguments = $original -split ' '
    $arguments = $arguments |foreach {"'$_'"}
    $arguments = $arguments -join ' '
    $final = $command + ' ' + $arguments
    "calling $final`n"

    invoke-expression $final

    by nohandle at 2012-12-17 10:16:46

    Thanks Aleksandar for pointing out what I wanted to mention but forgot it.
    There is a new operator in Powershell version 3 that addresses this type of operations. It is the stop parsing operator –% that forces powershell to take rest of the line as is. Really usefull when working with native commands.
    netsh --% http add sslcert ipport=0.0.0.0:443 certhash=DB76AF93AAB3E202A5C4EA5DE5E2E3704816623A appid={d673f5ee-a714-454d-8de2-492e4c1bd8f8}

You must be logged in to reply to this topic.