1

I'm trying to do something like this (tried to make it look like a table, but wasn't working with markdown,html or bunch of spaces):

Column1

Location info
Location #
Location name
Location phone
Location address

Column2

[blank]
1
NYC
789-987-1234
12 Some Blvd

Column3

Network info
Location Octet
External IP
Some other IP
More Ips

Column4

[blank]
345
10.89.52.468
10.346.345.1
10.326.345.2

I've tried creating new objects, converting arrays/hash to csv and then back and I'm having no luck. I've read some other threads but they all incorporate the use of cmdlets that create objects already and just working with that. I thought convert from csv did that, and it does I think, but how Im converting it back may be off. The above table is thus 6 columns and 5 rows, the top row having column 2 and 4 being blank.

I'd really like to learn how to do this, since I'll probably be employing it for other tasks as well.

3
  • Show what you've done so far and explain what's wrong with those. Commented Oct 21, 2014 at 5:38
  • Were do this data come from btw? Or do you want to create an object with static manually input data? Commented Oct 21, 2014 at 6:00
  • Manually input data. or in the long run from a csv file. Commented Oct 25, 2014 at 2:18

1 Answer 1

3

I believe you are trying to achieve something like this? :

$col1=@("Location info","Location #","Location name","Location phone","Location address");
$col2=@("","1","NYC","789-987-1234","12 Some Blvd");
$col3=@("Network info","Location Octet","External IP","Some other IP","More Ips");
$col4=@("","345","10.89.52.468","10.346.345.1","10.326.345.2");

$hash=@{"Column1"=$col1;"Column2"=$col2;"Column3"=$col3;"Column4"=$col4};
$obj = New-Object PSObject -Property $hash
$obj|Format-Table -Wrap -AutoSize

You will get the data as you've specified. You can use -ExpandProperty "Column1" (e.g. if you want to expand on all it's values). You can use ConvertTo-Html if you like to create a html-table of the data.

However, I would consider structuring the data in another fasion. How about keeping this data in seperate objects instead of formatting it in this way?

You could e.g. have a set of objects with the properties representing what you want. E.g. objects having the representative data :

 $obj = new-object PSObject -Property @{"Location info"="My loc"; "Location #"="My location"}
 $obj2 = new-object PSObject -Property @{"Location info"="My loc2"; "Location #"="My location2"}
 $myLocations = @($obj,$obj2);

That'd be more representative, and you could play and format the $myLocations for the properties you'd want.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.