# Create custom object

**URL:** <https://forums.powershell.org/t/create-custom-object/10310>\
**Category:** PowerShell Help\
**Created:** [March 15, 2018, 1:59pm UTC](https://forums.powershell.org/t/create-custom-object/10310 "2018-03-15T13:59:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![vandrey-trindade](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/vandrey-trindade/32/198_2.png) [@vandrey-trindade](https://forums.powershell.org/u/vandrey-trindade)\
**Post date:** [March 15, 2018, 1:59pm UTC](https://forums.powershell.org/t/create-custom-object/10310/1 "2018-03-15T13:59:02Z")

</div>

Hi,

I’m trying to create a custom object that has values from three different variables.  
Imagine this scenario:

Variable1 content:  
User1  
User2  
User3

Variable2 content:  
User5  
User7  
User8

Variable3 content:  
User10  
User12  
User20

I want to create an object that is something like this:  
“Local Admins”;“Remote Desktop”;“Logons”  
User1;User5;User10  
User2;User7;User12  
User3;User8;User20

Is there a way?

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [March 15, 2018, 2:02pm UTC](https://forums.powershell.org/t/create-custom-object/10310/2 "2018-03-15T14:02:06Z")

</div>

Of course.

```
$props = @{ColumnA = $var.Value1
           ColumnB = $var.Value2}
New-Object -Type PSObject -Prop $props
```

That’s the basic format. Do that for each row you want to produce. If you need the final result to be delimited with semicolons, as in your example, collect those rows into a variable and:

$AllRows | ConvertTo-CSV -Delim “;”

And you’ll get a semicolon-delimited set.

---

<div class="post-metadata">

**Author:** ![vandrey-trindade](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/vandrey-trindade/32/198_2.png) [@vandrey-trindade](https://forums.powershell.org/u/vandrey-trindade)\
**Post date:** [March 15, 2018, 2:05pm UTC](https://forums.powershell.org/t/create-custom-object/10310/3 "2018-03-15T14:05:08Z")

</div>

Don Jones,

Wow, you’re fast!  
But how can I do it when I don’t know how many values are in those variables?  
For example: Variable1 can have 3 values, Variable2 can have 10 values and Variable3 can have 6 values…

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [March 15, 2018, 2:07pm UTC](https://forums.powershell.org/t/create-custom-object/10310/4 "2018-03-15T14:07:54Z")

</div>

Mmm, that’s not really how objects work. Objects don’t have variable numbers of properties. If your end goal is that example you provided, then that’s not a good format for variable data. Meaning, if one machine can have multiple “Local Admins,” PowerShell can represent that in an object, but it becomes hierarchical data. You can’t represent hierarchical data in a flat file.

Think of an Excel sheet. If you were to do this in an Excel sheet, how would you put multiple values into a single cell for “Local Admins” on one machine? Maybe you’re thinking, “oh, I’d just do like commas between them,” and that might be fine for you as a human, but it’s a sucky data format for computers to deal with. That’s why computers have relational databases instead of doing everything in CSV files or Excel sheets.

So what’s the end goal, here? What are you trying to get to?

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [March 15, 2018, 7:18pm UTC](https://forums.powershell.org/t/create-custom-object/10310/5 "2018-03-15T19:18:37Z")

</div>

Ditto to what DonJ stated here.

Yet, you’d also might want to wrap you head around PoSH multi-dimensional arrays.

See these discussions.

> Today I want to talk a little about multidimensional arrays in Windows Powershell. Multidimensional arrays are one of the complex data types supported by Powershell. They can be used to dynamically store information in a volatile table without having it written to a real database in a file on the disk.
> 
> ‘[Streaming Tips For Beginners - StreamTipz](http://happysysadm.com/2011/01/multidimensional-arrays-in-powershell.html)’

> Easily Create and Manipulate an Array of Arrays in PowerShell 'blogs.technet.microsoft.com/heyscriptingguy/2011/12/09/easily-create-and-manipulate-an-array-of-arrays-in-powershell'

> Comparing two multi-dimensional arrays 'powershell.org/forums/topic/comparing-two-multi-dimensional-arrays'

---

<div class="post-metadata">

**Author:** ![vandrey-trindade](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/vandrey-trindade/32/198_2.png) [@vandrey-trindade](https://forums.powershell.org/u/vandrey-trindade)\
**Post date:** [March 16, 2018, 6:33am UTC](https://forums.powershell.org/t/create-custom-object/10310/6 "2018-03-16T06:33:04Z")

</div>

Don Jones and postanote,

I need to create a report of users that are in the local Admins, Remote Desktop users and who logged on multiple servers.  
I was able to create a TXT with that information, but I was trying to create an HTML with that info side by side.  
Microsoft auditing reasons.  
But that’s ok, I think I’ll try to use an Excel file to output the data…  
I’ll take a look at those sites postanote!

Thanks for your time and attention!!!

---

<div class="post-metadata">

**Author:** ![js2010](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@js2010](https://forums.powershell.org/u/js2010)\
**Post date:** [March 16, 2018, 9:11am UTC](https://forums.powershell.org/t/create-custom-object/10310/7 "2018-03-16T09:11:36Z")

</div>

Hey Don, anything wrong with making objects this way?

```
[pscustomobject]@{ColumnA = $var.Value1
                  ColumnB = $var.Value2}
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:36pm UTC](https://forums.powershell.org/t/create-custom-object/10310/8 "2024-05-16T20:36:12Z")

</div>

Closed on May 16, 2024, 8:36pm UTC


