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?
Technology Tips and News
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?
Hi Aurimas,
you do this using the cmdlet ConvertFrom-Csv. Example:
"a,b,c,d" | ConvertFrom-Csv -Header "Name","Type","Description","Location"
Cheers,
Fred
Help New-Object -full
http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx
$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
Thanks everyone, much appreciated.
$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