0

I'm trying to pass a parameter from the command line in powershell that works as long as there's no space in the parameter. How do I get it to continue to recognize it even with a space?

[Parameter(Mandatory=$True)]
[string]$EmailSubject,

If I run powershell ./Get-Attachment.ps1 -EmailSubject "New files" it will complain A positional parameter cannot be found that accepts argument 'files'

If I run powershell ./Get-Attachment.ps1 -EmailSubject "New" it has no issue.

If I run powershell ./Get-Attachment.ps1 it will prompt me for the EmailSubject then I can put in "New files" and it has no issue.

whoisearth
  • 4,080
  • 13
  • 62
  • 130
  • correct in that doing '"New files"' resolved the problem. Of interest that 'New Files' works so apparently powershell is dumb when it comes to double quotes but not with single quotes? I'm guessing internally it's wrapping the "" which is why it fails? – whoisearth Oct 21 '15 at 16:06
  • 1
    I think what is happening is that the double quotes are being consumed by the shell first, passing the contents as a single parameter to powershell, but the contents don't contain the quotes. – briantist Oct 21 '15 at 16:14

0 Answers0