作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 PowerShell 中,我想将 CSV 文件中的标题名称传递给 PowerShell 脚本中的另一个函数。
如何将标题名称的值文本检索到 CSV 中的变量中?
例如如果我有以下 CSV 数据:
ID Name Country
-- ---- -------
1 John United States
2 Beatrice Germany
3 Jouni Finland
4 Marcel France
function GetItemIdFromTitle([string]$LookupTitle, [ref]$LookupId)
{
$LookupField = $LookupList.Fields["DEPTCATEGORY"]
$LookupItem = $LookupList.Items | where {$_['DEPTCATEGORY'] -like "*$LookupTitle*"}
$LookupId.Value = $LookupItem.ID
}
#GET THE LOOKUP COLUMN ID
GetItemIdFromTitle $_.DEPTCAT ([ref]$LookupIdValue)
$myCountryColumnName = $_.Country.Property.Title
$myCategoryColumnName = $_.DEPTCAT.Property.Name
最佳答案
如果你在 $obj 中有一个对象,你可以像这样列出所有的属性头:
$obj | Get-member -MemberType 'NoteProperty' | Select-Object -ExpandProperty 'Name'
($obj | Get-member -MemberType 'NoteProperty' | Select-Object -ExpandProperty 'Name')[0]
关于powershell - 如何获取 CSV 中标题的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25764366/
我是一名优秀的程序员,十分优秀!