0

I have this line of code

"$FTE = Get-DynamicDistributionGroup '" + Input.SelectedItem.Text + "'";

And if my selected item is daddy then the output would be

Get-DynamicDistributionGroup 'daddy'

However is my item is daddy's

then the string has an extra '

Get-DynamicDistributionGroup 'daddy's'

How should I format this so that the " or ' contains the apostrophe I tried a few ideas but none seem to work for all occasions.

GSerg
  • 76,472
  • 17
  • 159
  • 346
DevilWAH
  • 2,553
  • 13
  • 41
  • 57
  • @Yuck That might not be a duplicate because the OP is apparently generating a powershell script with C# and wants to escape quotes according to powershell rules. – GSerg Dec 01 '16 at 11:31
  • Possible duplicate of [Escape characters when generating Powershell scripts using C#](http://stackoverflow.com/q/15245119/11683) – GSerg Dec 01 '16 at 11:34
  • 1
    Also see this: http://serverfault.com/questions/47811/what-is-the-literal-escape-character-in-powershell – Peter B Dec 01 '16 at 11:34
  • Indeed the first answer suggested does not work for putting quotes around the input.selecitem.text variable when inserting it in to the string. Or at least I cant get it to – DevilWAH Dec 01 '16 at 11:35
  • OK it was a bit of trial and error as some combinations the power shell did not like in the end i put + "\"" + at the ends of each string and it finally seemed to accept it. – DevilWAH Dec 01 '16 at 12:15

0 Answers0