You must provide a value expression following the '-' operator.

Welcome Forums General PowerShell Q&A You must provide a value expression following the '-' operator.

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

 
Participant
1 year, 1 month ago.

  • Author
    Posts
  • #81184

    Participant
    Points: 14
    Rank: Member

    i'm trying to splat some information for export purposes.

    the entry is:
    "Department" = $entry.USA_-_CF_-_Evaluate_Sup_Org_Name

    when this runs i recieve:
    At line:112 char:42
    + "Department" = $entry.USA_-_CF_-_Evaluate_Sup_Org_Name
    + ~
    You must provide a value expression following the '-' operator.

    if i export the data that i am looping through, the header as shown above is the actual header.

    i have tried ` the – signs :
    "Department" = $entry.USA_`-_CF_`-_Evaluate_Sup_Org_Name

    but receive this error then:
    At line:112 char:42
    + "Department" = $entry.USA_-_CF_-_Evaluate_Sup_Org_Name
    + ~
    You must provide a value expression following the '-' operator.

    completely stumped here, any assistance would be appreciated

  • #81187

    Keymaster
    Points: 1,619
    Helping HandTeam Member
    Rank: Community Hero

    Yeah, the problem is that dashes aren't technically legal as property names. The parser is choking on it.

    Try surrounding the property name in {curlies}, e.g., $variable.{This-is-not-great}.

  • #81197

    Participant
    Points: 0
    Rank: Member

    You could also use double or single quotes.

    $object = [pscustomobject]@{
        Name = "test"
        'USA_-_CF_-_Evaluate_Sup_Org_Name' = "some data"
    }
    
    $object.{USA_-_CF_-_Evaluate_Sup_Org_Name}
    $object.'USA_-_CF_-_Evaluate_Sup_Org_Name'
    $object."USA_-_CF_-_Evaluate_Sup_Org_Name"
  • #81221

    Participant
    Points: 14
    Rank: Member

    Thanks Don, wrapping the property name in {} did the trick

The topic ‘You must provide a value expression following the '-' operator.’ is closed to new replies.