【发布时间】:2021-08-05 10:21:16
【问题描述】:
您能告诉我如何添加一个 csv 文件,以便将每个变量的数据写入所需的列吗?为每个新循环换一个新行?
New-Item -Path . -Name "Test.csv" -ItemType "file" -force | Out-Null
("" | Select-Object Date, RAM_1, RAM_2, RAM_3, RAM_Used_total_%, RAM_Free%, CPU_Load% | ConvertTo-Csv -NoType -Delimiter ";")[0] | Out-File '.\Test.csv'
# Start the while loops
while($true) {
# In which data is collected into variables that need to be entered into each of the columns, respectively
$date
$RAM_1
$RAM_2
$RAM_3
$RAM_Usage
$Free_RAM
$CPU_Load
Start-Sleep -s 60
}
提前谢谢你
【问题讨论】:
-
看看
Export-Csv- 诀窍是创建具有与列对应的属性名称的对象(而不是单个变量) - 与您当前创建的方式相同带有Select-Object的空对象
标签: powershell csv