Powershell 将Invoke Webrequest转换为字符串以在csv文件中使用,格式有问题

Powershell 将Invoke Webrequest转换为字符串以在csv文件中使用,格式有问题,powershell,Powershell,我正在尝试将ppro状态网站的输出转换为csv格式,然后我可以使用。我已经获得了下面所需的数据,但我无法将其转换为csv格式。有人能告诉我我做错了什么吗 $URL = "https://status.ppro.com/" $req = Invoke-Webrequest -URI $URL $name = $req.ParsedHtml.getElementsByClassName("name") | ForEach-Object{Write-Output

我正在尝试将ppro状态网站的输出转换为csv格式,然后我可以使用。我已经获得了下面所需的数据,但我无法将其转换为csv格式。有人能告诉我我做错了什么吗

$URL = "https://status.ppro.com/"
$req = Invoke-Webrequest -URI $URL
$name = $req.ParsedHtml.getElementsByClassName("name") | ForEach-Object{Write-Output $_.innerhtml}
$Status = $req.ParsedHtml.getElementsByClassName("component-status") | ForEach-Object{Write-Output 
$_.innerhtml} 

$Counter=0
foreach($row in $name)
{

$nameString = $name[$Counter] | Out-String
$statusString = $Status[$Counter] | Out-String
$Output += Write-Output "$nameString, $statusString"
#$hash[$nameString] = $statusString

$Counter++
}
Write-Output "Name,status"
$Output | Out-File  -FilePath "C:\Users\test\test123.csv" 
下面是我试图实现的输出示例

姓名、身份

Girogate:交易处理平台,可操作

Girogate:事务重定向器,可操作


谢谢

也许不太理想,但这确实有效:

$Output=$null
# Create the output file in the invocation path\Logs with a date-coded name
# The .\Logs file must exist prior to execution.
$OutFile = $MyInvocation.MyCommand.Path.Replace($MyInvocation.MyCommand.Name,"Logs\") + ((Get-Date).AddDays(-1).ToString('yyyy_MM_dd')) + ".csv"
$URL = "https://status.ppro.com/"
$req = Invoke-Webrequest -URI $URL
$name = $req.ParsedHtml.getElementsByClassName("name") | ForEach-Object{Write-Output $_.innerhtml}
$Status = $req.ParsedHtml.getElementsByClassName("component-status") | ForEach-Object{Write-Output $_.innerhtml} 

$Counter=0
Write-Output "Name,status"
foreach($row in $name)
{

$nameString = (($name[$Counter]).trim()).replace("`r","").replace("`n","")
$statusString = (($Status[$Counter]).replace("`n","").replace("`r","")).trim()  | Out-String
$Output += Write-Output "$nameString,$statusString"
#$hash[$nameString] = $statusString
$Counter++
}
$Output > $OutFile

感谢Darrell,这对我来说很有用,尽管我仍然不知道为什么不能使用export csv函数导出$output