-1

I have an array of comma separated data that I need to do operations on. In the past I would write to a file then Import-Csv that file back to a variable. Is there anyway to split the data into columns?

Sample 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,enroll@domain.org,0151f63c,Lenovo N21 Chromebook,/Devices/2nd,,,,,,,,,,
ACTIVE,2016-03-07T21:12:50.856Z,2015-10-14T18:27:36.757Z,NXSHEAAXXXXXX,enroll@domain.org,01cc8dd9,Acer C720 Chromebook,/Devices/1st,,,,,,,,,,

Here is the format I get when exporting to a CSV then importing back in:

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    enroll@domain.org    0151f63c    Lenovo N21 Chromebook    /Devices/2nd/H...
ACTIVE    2016-03-07T21:12:50.856Z    2015-10-14T18:27:36.757Z    NXSHEAAXXXXXX    enroll@domain.org    01cc8dd9    Acer C720 Chromebook    /Device...
  • What format are you looking for? – soandos Mar 8 '16 at 14:06
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,enroll@domain.org,0151f63c,Lenovo N21 Chromebook,/Devices/2nd,,,,,,,,,,
ACTIVE,2016-03-07T21:12:50.856Z,2015-10-14T18:27:36.757Z,NXSHEAAXXXXXX,enroll@domain.org,01cc8dd9,Acer C720 Chromebook,/Devices/1st,,,,,,,,,,
'@

convertfrom-csv -InputObject $string | FormatTable -AutoSize

Gives you this:

status lastSync                 lastEnrollmentTime       serialNumber  annotatedUser     deviceId model                 orgUnitPath  macAddress willAutoRenew
------ --------                 ------------------       ------------  -------------     -------- -----                 -----------  ---------- -------------
ACTIVE 2016-03-07T21:09:12.333Z 2015-07-07T18:05:47.849Z LRXXXXXX      enroll@domain.org 0151f63c Lenovo N21 Chromebook /Devices/2nd                         
ACTIVE 2016-03-07T21:12:50.856Z 2015-10-14T18:27:36.757Z NXSHEAAXXXXXX enroll@domain.org 01cc8dd9 Acer C720 Chromebook  /Devices/1st    

Please let me know if this is the answer you're looking for. Your question is a bit vague.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.