Author Posts

October 3, 2017 at 7:54 pm

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

October 3, 2017 at 8:00 pm

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}.

October 4, 2017 at 12:17 am

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"

October 4, 2017 at 11:36 am

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