0

I need to generate some commands with a PowerShell script, but I can't print the $ symbol.

Write-Host "Add-MailboxPermission -Identity $ Mailbox -User $ User -AccessRight FullAccess -Automapping $false"

generates:

Add-MailboxPermission -Identity MAILBOX -User USER-AccessRight FullAccess -Automapping False
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dennis
  • 29
  • 4
  • Is this meant to be some sort of Verbose for your sciprt? – Santiago Squarzon Jul 28 '21 at 20:52
  • Use single quotes for verbatim output -> `Write-Host 'Add-MailboxPermission -Identity $Mailbox -User $User -AccessRight FullAccess -Automapping $false'` – AdminOfThings Jul 28 '21 at 21:11
  • Does this answer your question? [How to escape special characters in PowerShell?](https://stackoverflow.com/questions/57965466/how-to-escape-special-characters-in-powershell) – phuclv Jul 29 '21 at 01:23
  • [Escaping dollar signs in PowerShell path is not working](https://stackoverflow.com/q/17452401/995714), [PowerShell script not accepting $ (dollar) sign](https://stackoverflow.com/q/1615117/995714) – phuclv Jul 29 '21 at 01:28

1 Answers1

1

Write-Host "`$" works.

In general when programming, special characters need escaping to be printed. Many language use \ to escape, PowerShell uses ` (the backtick, to the left of the 1 on your keyboard).

mklement0
  • 382,024
  • 64
  • 607
  • 775
bschellekens
  • 191
  • 6
  • 2
    To the left of the `1` on my keyboard, I have `°` and `§` ...... remember: **not everyone** in the whole world is using an US-English keyboard....... there *are* other languages, locales, and keyboard layouts out there.... – marc_s Jul 28 '21 at 20:39
  • why Add-MailboxPermission -Identity $ Mailbox -User $ User -AccessRight FullAccess -Automapping $false is not recognized as command? – Dennis Jul 29 '21 at 16:04