我有一个逗号分隔的数据数组,需要对其进行操作。过去,我会将其写入文件,然后使用 Import-Csv 将该文件返回到变量。有没有办法将数据拆分成列?
样本数据:
status,lastSync,lastEnrollmentTime,serialNumber,annotatedUser,deviceId,model,orgUnitPath,macAddress,willAutoRenew,orderNumber,meid,supportEndDate,osVersion,ethernetMacAddress,bootMode,platformVersion,firmwareVersion
ACTIVE,2016-03-07T21:09:12.333Z,2015-07-07T18:05:47.849Z,LRXXXXXX,[email protected],0151f63c,Lenovo N21 Chromebook,/Devices/2nd,,,,,,,,,,
ACTIVE,2016-03-07T21:12:50.856Z,2015-10-14T18:27:36.757Z,NXSHEAAXXXXXX,[email protected],01cc8dd9,Acer C720 Chromebook,/Devices/1st,,,,,,,,,,
这是我导出到 CSV 然后重新导入时获得的格式:
status lastSync lastEnrollmentTime serialNumber annotatedUser deviceId model orgUnitPath macAddress willAutoRenew orderNumber meid supportEndDateosVersion ethernetMacAddress bootMode platformVersion firmwareVersion
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ACTIVE 2016-03-07T21:09:12.333Z 2015-07-07T18:05:47.849Z LRXXXXXX [email protected] 0151f63c Lenovo N21 Chromebook /Devices/2nd/H...
ACTIVE 2016-03-07T21:12:50.856Z 2015-10-14T18:27:36.757Z NXSHEAAXXXXXX [email protected] 01cc8dd9 Acer C720 Chromebook /Device...
答案1
$string = @'
status,lastSync,lastEnrollmentTime,serialNumber,annotatedUser,deviceId,model,orgUnitPath,macAddress,willAutoRenew,orderNumber,meid,supportEndDate,osVersion,ethernetMacAddress,bootMode,platformVersion,firmwareVersion
ACTIVE,2016-03-07T21:09:12.333Z,2015-07-07T18:05:47.849Z,LRXXXXXX,[email protected],0151f63c,Lenovo N21 Chromebook,/Devices/2nd,,,,,,,,,,
ACTIVE,2016-03-07T21:12:50.856Z,2015-10-14T18:27:36.757Z,NXSHEAAXXXXXX,[email protected],01cc8dd9,Acer C720 Chromebook,/Devices/1st,,,,,,,,,,
'@
convertfrom-csv -InputObject $string | FormatTable -AutoSize
给你这个:
status lastSync lastEnrollmentTime serialNumber annotatedUser deviceId model orgUnitPath macAddress willAutoRenew
------ -------- ------------------ ------------ ------------- -------- ----- ----------- ---------- -------------
ACTIVE 2016-03-07T21:09:12.333Z 2015-07-07T18:05:47.849Z LRXXXXXX [email protected] 0151f63c Lenovo N21 Chromebook /Devices/2nd
ACTIVE 2016-03-07T21:12:50.856Z 2015-10-14T18:27:36.757Z NXSHEAAXXXXXX [email protected] 01cc8dd9 Acer C720 Chromebook /Devices/1st
请告诉我这是否是您想要的答案。您的问题有点模糊。