Mengubah array PowerShell ke dalam tabel

-1

Saya memiliki array data yang dipisahkan koma yang harus saya lakukan operasi. Di masa lalu saya akan menulis ke file lalu Impor-Csv file itu kembali ke variabel. Apakah ada cara untuk membagi data menjadi kolom?

Contoh data:

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,,,,,,,,,,

Ini adalah format yang saya dapatkan ketika mengekspor ke CSV kemudian mengimpor kembali:

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...
CML
sumber
Format apa yang Anda cari?
soandos

Jawaban:

4
$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

Memberi Anda ini:

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    

Tolong beri tahu saya jika ini adalah jawaban yang Anda cari. Pertanyaan Anda agak kabur.

megamorf
sumber