Forum Discussion

RandyRiauka's avatar
RandyRiauka
Copper Contributor
Sep 03, 2022
Solved

Message: There is an unterminated string literal at position 46 in ... (Special Charater the cause)

Hi, I'm hoping someone can guide me on an issue I'm having with the error message "Message: There is an unterminated string literal at position 46 in ..."   I know the cause but am unsure of the sol...
  • LainRobertson's avatar
    Sep 03, 2022

    RandyRiauka 

     

    Hi, Randy.

     

    Using web-specific special characters in resources never ends well, as you're seeing. Fortunately, there is a reasonably straight-forward solution as there's many ways to encode such strings.

     

    Here's one that uses the [uri] class to escape the displayName properly.

     

     

    Using your example:

    # This:
    Get-Team -DisplayName "Peer Tutoring - Metal Fabrication & Welding";
    
    # Becomes this:
    Get-Team -DisplayName ([uri]::EscapeDataString("Peer Tutoring - Metal Fabrication & Welding"))

     

    Cheers,

    Lain

Resources