Powershell System.Array转换为CSV文件 [英] Powershell System.Array to CSV file
本文介绍了Powershell System.Array转换为CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很难让Export-Csv正常工作.我正在创建一个像这样的数组...
I am having some difficulty getting an Export-Csv to work. I am creating an array like this...
[pscustomobject] @{
Servername = $_.Servername
Name = $_.Servername
Blk = ""
Blk2 = ""
Method = "RDP"
Port = "3389"
}
我遇到的问题是,当我尝试将其导出到CSV时,我得到了如下所示的垃圾...
The issue I have is when I try to export that to a CSV I get garbage that looks like this...
"9e210fe47d09416682b841769c78b8a3" ,,,,
"9e210fe47d09416682b841769c78b8a3",,,,,
我已经阅读了大量有关此问题的文章,但我只是不明白如何正确获取数据.
I have read a ton of articles addressing this issue, but I just don't understand how to get the data right.
推荐答案
为了进行测试,我构建了一个带服务器名称的CSV文件,并读取了该文件,并且在PS4中可以使用以下功能:
For testing, I built a CSV file w/ the servernames, and read it in, and the following works in PS4:
$serverList = import-csv "datafile.csv"
$AllObjects = @()
$serverList | ForEach-Object {
$AllObjects += [pscustomobject]@{
Servername = $_.Servername
Name = $_.Servername
Blk = ""
Blk2 = ""
Method = "RDP"
Port = "3389"
}
}
$AllObjects | Export-Csv -Path "outfile.csv" -NoTypeInformation
这篇关于Powershell System.Array转换为CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文