Powershell:引用包含空格的属性 [英] Powershell: Reference a property that contains a space
本文介绍了Powershell:引用包含空格的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用powershell导入CSV文件。
问题是,其中一列的标题是剩余时间 - 小时。
所以我得到一个对象序列,它实际上被分配属性剩余时间 - 小时。
属性?
例如
Import-Csv AllOpenCases.csv | %{$ case = $ _}
$ case | get-member
返回
类别:查询
已加星标:无
剩余时间 - 小时:22.5
b $ b
但如果我输入
$ case.Remaining时间 - 小时
我在表达式或语句中得到意外的令牌'时间'
解决方案具有嵌入空格的属性必须在引用时引用:
$ case。剩余时间 - 小时
I am importing a CSV file using powershell.
The problem is, the title of one of the columns is "Remaining Time - Hours". So I'm getting a sequence of objects, and it's actually assigned the property "Remaining Time - Hours".
What is the syntax to refer to this property?
eg
Import-Csv AllOpenCases.csv | % {$case = $_ } $case | get-member
returns
Category : Inquiry Starred : No Remaining Time - Hours : 22.5
but if I type
$case.Remaining Time - Hours
I get "Unexpected token 'Time' in expression or statement"
解决方案Properties with embedded spaces have to be quoted when they're referenced:
$case."Remaining Time - Hours"
这篇关于Powershell:引用包含空格的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文