【问题标题】:Export to CSV only returning string length导出到 CSV 仅返回字符串长度
【发布时间】:2016-08-10 14:01:42
【问题描述】:

我正在尝试将此脚本导出到 CSV 文件,它只列出字符串长度,而不是我要提取的电子邮件。

Get-ADGroup -filter {name -like 'Security Group'} | 
    Get-ADGroupMember -Recursive |
    Get-ADUser -Properties Mail |
    select -ExpandProperty Mail |
    Export-Csv -NoType MyCSVfile1.csv

【问题讨论】:

  • 哇,我觉得自己像个傻瓜。非常感谢!

标签: powershell export-to-csv


【解决方案1】:

Export-Csv 期望接收一个对象,你给了它一个字符串,所以它在输出文件中为你提供了该字符串的属性(即Length)。

删除-ExpandProperty 就可以了。

Get-ADGroup -filter {name -like 'Security Group'} |
    Get-ADGroupMember -Recursive |
    Get-ADUser -Properties Mail |
    Select Mail |
    Export-Csv -NoType MyCSVfile1.csv

【讨论】:

  • 否则只需将值列表写入文件:... | Select -Expand Mail | Set-Content MyCSVfile1.csv
猜你喜欢
  • 2019-03-14
  • 2015-07-03
  • 2019-04-18
  • 2013-05-02
  • 2018-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多