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

This topic contains 3 replies, has 3 voices, and was last updated by  David Schmidtberger 1 week, 5 days ago.

  • Author
    Posts
  • #81184

    David Schmidtberger
    Participant

    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

    Don Jones
    Keymaster

    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

    Curtis Smith
    Participant

    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

    David Schmidtberger
    Participant

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

You must be logged in to reply to this topic.