-1

I am trying to invoke the following the command which contains the single quotation, but I am not able to execute and returns as an error:

$expression = $snapshot.properties.activities[1].typeProperties.parameters.rawinputlocation = '$$Text.Format(`'wasb://document.blob.co
re.windows.net/{0:yyyy}/{0:MM}/{0:dd}/DocumentActivity/raw/{{*}}.csv'`, SliceEnd)'

 Invoke-Expression $expression

Error:

  • Invoke-Expression $expression
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : ParserError: (:) [Invoke-Expression], ParseException
    • FullyQualifiedErrorId : UnexpectedToken,Microsoft.PowerShell.Commands.InvokeExpressionCommand
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dipti Mamidala
  • 153
  • 2
  • 10
  • Create a [MCVE](https://stackoverflow.com/help/mcve). As of now, all there is is a code fragment that doesn't do much sense. – vonPryz Dec 01 '17 at 07:57
  • See also *[Invoke-Expression considered harmful](https://blogs.msdn.microsoft.com/powershell/2011/06/03/invoke-expression-considered-harmful/)*. – Peter Mortensen Sep 08 '18 at 15:04

1 Answers1

0

This happens as the single quote, ', is escaped with a backtick, `.

The first one works, but the latter one is in the wrong order: the backtick is after the single quote. Consider the difference:

`'wasb://...csv'`
`'wasb://...csv`'
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
vonPryz
  • 22,996
  • 7
  • 54
  • 65