我会使用 Export-CSV 来做到这一点。将您的值收集到对象并导出。前任:
#Create objects(think lines in a tsv) with properties and values
$o1 = New-Object psobject -Property @{
Property1 = "Val1o1"
Property2 = "Val2o1"
Property3 = "Val3o1"
}
$o2 = New-Object psobject -Property @{
Property1 = "Val1o2"
Property2 = "Val2o2"
Property3 = "Val3o2"
}
#Collect to array
$o = $o1, $o2
#Save to TSV
$o | Export-Csv "c:\test.tsv" -Delimiter `t -NoTypeInformation
#Add content
$o3 = New-Object psobject -Property @{
Property1 = "Val1o3"
Property2 = "Val2o3"
Property3 = "Val3o3"
}
#Append to TSV-file
$o3 | Export-Csv "c:\test.tsv" -Delimiter `t -NoTypeInformation -Append
#To read file back to PowerShell objects
$a = Import-Csv "C:\test.tsv" -Delimiter `t
测试.tsv
"Property1" "Property2" "Property3"
"Val1o1" "Val2o1" "Val3o1"
"Val1o2" "Val2o2" "Val3o2"
"Val1o3" "Val2o3" "Val3o3"