Comma delimited string to Object

Hello,

I have a string: "a,b,c,d" my desire is to have an object with properties Name=a, Type=b, Description=c, Location=d

how can I dot that?

August 21st, 2015 4:33am

Hi Aurimas,

you do this using the cmdlet ConvertFrom-Csv. Example:

"a,b,c,d" | ConvertFrom-Csv -Header "Name","Type","Description","Location"

Cheers,
Fred

Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 4:39am

Help New-Object -full

http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

August 21st, 2015 4:39am

$string = "a,b,c,d"

$CO = New-Object PSObject           
$CO | Add-Member -Name 'Name' -MemberType NoteProperty -Value $string.Split(',')[0]
$CO | Add-Member -Name 'Type' -MemberType NoteProperty -Value $string.Split(',')[1]
$CO | Add-Member -Name 'Description' -MemberType NoteProperty -Value $string.Split(',')[2]
$CO | Add-Member -Name 'Location' -MemberType NoteProperty -Value $string.Split(',')[3]

$CO

  • Marked as answer by Aurimas N 21 hours 56 minutes ago
Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 4:42am

Thanks everyone, much appreciated.

August 21st, 2015 5:17am

$string = "a,b,c,d"

$CO = New-Object PSObject           
$CO | Add-Member -Name 'Name' -MemberType NoteProperty -Value $string.Split(',')[0]
$CO | Add-Member -Name 'Type' -MemberType NoteProperty -Value $string.Split(',')[1]
$CO | Add-Member -Name 'Description' -MemberType NoteProperty -Value $string.Split(',')[2]
$CO | Add-Member -Name 'Location' -MemberType NoteProperty -Value $string.Split(',')[3]

$CO

  • Marked as answer by Aurimas N Friday, August 21, 2015 9:13 AM
Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 8:39am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics