Single quote in a string

Welcome Forums General PowerShell Q&A Single quote in a string

This topic contains 2 replies, has 3 voices, and was last updated by

 
Participant
1 year, 11 months ago.

  • Author
    Posts
  • #59825

    Participant
    Points: 0
    Rank: Member

    Hi Everyone

    I am dealing with displayName attribute in AD. I am dumping these names into an Oracle table. Some names have a single quote in them. For example – Jerry O'Brian

    In my script I am using single quotes around the variable. Like this – '$displayName'
    The script throws an exception when it finds that name. So I get all names into the table except this.

    I tried using double quotes, two single quotes, tried different escape characters. Nothing worked. Any ideas?

    I am hoping someone can help.

    Thanks
    Mohan

  • #59827

    Participant
    Points: 2
    Rank: Member

    What command are you running that returns the error? What is the content of the error message? There's no particular issue with having a single quote in a string variable, but maybe the particular command you're running is balking at it, and you might need to do some error handling. Or maybe the database field has a problem with it?

  • #59830

    Participant
    Points: -12
    Rank: Member

    Hi

    Single quotas outside variable will convert the variable name into a String and not how double quotas shows you what's inside the variable.

    Example:
    $variable = 'text'
    "$varible" returns: text
    '$variable' returns: $variable

    Jake

The topic ‘Single quote in a string’ is closed to new replies.