#1 09 Jan 2020 22:22

New Member
Registered: 09 Jan 2020
Posts: 1

a space in string trips it up

In PS context it works fine:
  PS C:\> Set-NetConnectionProfile -InterfaceAlias "Ethernet 2" -NetworkCategory private

Same thing fails when invoked in this way:
  C:\>powershell Set-NetConnectionProfile -InterfaceAlias "Ethernet 2" -NetworkCategory private
The error message is:
  A positional parameter cannot be found that accepts argument '2'


#2 10 Jan 2020 10:43

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 1,118

Re: a space in string trips it up

Thats because you are running it from a CMD shell, so you need to take into account the CMD shell's ancient and arcane handling of quotes.
This page has some examples:

By tripling the quotes, I think what's happening is that CMD parses that as a quote delimited string containing just a quote mark, so it strips the outer quotes and passes the one remaining quote through to PowerShell.

"""Ethernet 2"""
is seen by CMD as three strings, the first string is one quoted quote mark, the second string is the verbatim text and the third string is the last quoted quote mark.

That may not be actually how it works internally, but it's how I think of it to make sense of/remember the syntax.


Board footer

Powered by FluxBB