Custom object array inside of another custom object


What I would like to do is create a custom object called “_my_sub_object” and then define my main object called “_my_main_object” where one of the fields is an array of objects using my sub object definition.

What I need is an array of objects within an object. Any assistance would be appreciated.

add-type @"
public struct _my_sub_object {
public string MySubField01;
public string MySubField02;
public string MySubField03;


add-type @"
public struct _my_main_object {
public string MyObjField01;
public string MyObjField02;
public string MyObjField03;


# Create two PSCustomObject
$my_main_object = [pscustomobject]@{
public1 = 'MyObjField01'
public2 = 'MyObjField02'
public3 = 'MyObjField03'
$my_sub_object = [pscustomobject]@{
public1 = 'MySubField01'
public2 = 'MySubField02'
public3 = 'MySubField03'

# Add objects to hash table
$my_object = @{}
$my_object; $my_object.Values

Or you can create two hash tables then add to a $my_object
Ex: $main=@{};$sub=@{}

Sorry about not being clear about I was looking for.

I want to create a person object and an address object.
In the person object I want to have an array of address objects.

The address object must have 3 elements namely 1) Address type, 2) Street name and 3) State.

The person object must have 3 elements namely 1) Name, 2) Last name and 3) array of address objects.

Person (type/object)
Address (type/object)

Record # | Name | Last name | Address type | Street name | State |
1 John Doe Physical 100 Main str NY
Mailing P.O Box 123 NJ

2 Jane Doe Physical 500 Main str NY

It would be exceedingly helpful to see your input data.

I do not have any input data yet. I am trying to see if this structure is even possible. Think of the case of a server and it’s hard disks. You have a server object and a hard disk object. I want to create a function that collects information for a server and another function that collects information of a hard drive.

As a server can have multiple hard disks so the server object must contain an array of hard disk information.

Hope that helps.