[英]Getting a comma inserted between fields when exporting data using out-file Powershell
當我導出兩個字段時,它們顯示在彼此下方,而不是並排顯示。 我嘗試了export-csv,但只獲得了字段大小值而不是數據。 請指教。
$computername = (Get-item env:COMPUTERNAME).value
$One_Drive_Version = (Get-Item $env:userprofile\AppData\Local\Microsoft\OneDrive\OneDrive.exe).VersionInfo.FileVersion
$computername, $One_Drive_Version | Out-File "//SERVER/OneDriveVersion/onedriveVersion.csv" -force -append
($computername + "," + $One_Drive_Version) | Out-File //SERVER/OneDriveVersion/onedriveVersion.csv" -force -append
你去
手動將它們連接起來:
$output = "$computername,$One_Drive_Version" | Out-File ...
# or
$output = $computername,$One_Drive_Version -join ',' | Out-File ...
# then
或創建一個對象和管道到Export-Csv
:
[pscustomobject]@{
ComputerName = $computername
Version = $One_Drive_Version
} |Export-Csv "//SERVER/OneDriveVersion/onedriveVersion.csv" -Append -NoTypeInformation
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.