powershell - 将Powershell对象属性的名称值转换为字符串

标签 powershell powershell-2.0

我已导入一个csv文件

$infile = import-csv .\myfile.csv

现在,我可以通过显示列(现在是对象属性)
$infile | gm -type NoteProperty

Name      MemberType

-------   ----------

Column1   NoteProperty

Column2   NoteProperty

etc...

我要做的是将Name(Column1..)的值转换为变量。

最佳答案

您可以使用select

$infile | gm -type NoteProperty | select -ExpandProperty Name

例如。,
$Names = @( $infile | gm -type NoteProperty | select -ExpandProperty Name )

关于powershell - 将Powershell对象属性的名称值转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27068904/

相关文章:

powershell - 如果我不列出属性,比较对象不起作用

powershell - 有没有办法使用Powershell从Lotus Notes数据库中获取30分钟以上的文档?

windows - 如何让powershell脚本在同一终端执行批处理命令

c# - 在 PowerShell v2 中编译新类型 - Cookie Aware WebClient

c# - PowerShell 模块是否更接近 C# 中的类的 "thing"?

PowerShell 错误命令行太长

windows - 确保在任何给定时间只有 1 个 PowerShell 脚本实例正在运行

powershell - 如何从PS输出中过滤出特定值

powershell - 在文本文件中组织分类数据并转换为CSV的最快方法

powershell - -in 运算符在 2.0 版本中不起作用?