Powershell 数组到 csv

问题描述

我对 powershell 很陌生,我无法弄清楚如何将我的数组放入 csv 文件中,其中每个字符串都进入一个新行。下面是一些示例代码。

$ServerList = "E:\Coding Projects\Powershell\ServerNameList.txt"
$ServerNames = Get-content $ServerList
write-host $ServerNames
$OutputPath = "E:\Coding Projects\Powershell\Output.csv"

$Names = @() 
$Outcome = @()
foreach ($Server in $ServerNames){
    $Names += $Server 
    if ($Server -match "Joe"){
        $Outcome += "pass" 
       
    }else{
        $Outcome += "Fail" 
    }

}
$Names
$Outcome

$csv = New-object psobject -property @{ 
    'User' = $Names -join ',' 
    'Groups' = $Outcome -join ','
    }

write-host $csv

$csv | Select-Object -property User,Groups | Export-csv -path $OutputPath -NoTypeInformation

当我检查 csv 文件时,所有输出都出现在一行上,而不是在其特定列中向下迭代。 任何帮助都会非常有用和赞赏

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)