Questions tagged [pscustomobject]

Shorthand syntax for initializing object properties in powershell

Docs: MSDN - PSCustomObject

Powershell v2.0

$object = New-Object -TypeName PSObject -Property @{  ​
    'Name' = 'Susan'
    'Age' = 32
}

Powershell v3.0

$object = [PSCustomObject]@{  ​
    'Name' = 'Susan'
    'Age' = 32
}

See also:

165 questions
3
votes
1 answer

Does PSCustomObject have an order in which its displayed to the console?

Good morning peeps, Im a big fan of making a selection from values that are returned from listed items. So, I was expirementing with making a selection out of the values returned from C:\Users, which is input into a [PSCustomObject] type, but…
Abraham Zinala
  • 4,267
  • 3
  • 9
  • 24
3
votes
1 answer

psCustomObject as returned data, odd pipeline errors

I am attempting to satisfy my curiosity about return type performance. Basically I want to see if there is a meaningful difference between a hash table, a psCustomObject and my own class when returning complex data. But I am having issues with the…
Gordon
  • 6,257
  • 6
  • 36
  • 89
3
votes
2 answers

Powershell: PSCustomObject array as parameter in function gets changed unexpectedly

In the simplified PS code below, I don't understand why the $MyPeople array gets changed after calling the changeData function. This array variable should just be made a copy of, and I expect the function to return another array variable into…
Chris
  • 88
  • 1
  • 11
3
votes
2 answers

Powershell pscustomobject format-table new row instead of one line

I have a very large JSON response for employees that I am trying to get into table format, export to CSV and eventually insert into SQL Server. I was able to determine how to get all of my variables from the json file, however now I am getting all…
3
votes
1 answer

Define custom property sets (with Add-Member?) for use in Select-Object

What I try to do is quite simple: create a custom object with some properties, and then define "groups" of properties (columns) for use in Select-Object. Let me clarify: $props = @{"Mary"=1;"Jane"=2;"Frank"=3;"John"=5;"Brenda"=6} $obj = New-Object…
Joost
  • 1,126
  • 1
  • 10
  • 19
2
votes
2 answers

Creating custom objects and using the output

I'm using the following to read one line from a whole load of text files and then summarize that information into one file. $computers = Get-content computers.txt $users = users.csv $header = 'Computer','User','Date','Time' Foreach ($computer in…
fenster
  • 1,809
  • 6
  • 22
  • 24
2
votes
1 answer

Import-CSV: add rows (members) to resulting object in foreach loop

I am trying to achieve the following with imported CSV Data in Powershell: the CSV has the following structure: | FirstName | LastName | Tier | | --------- | ------- | ---- | | George | Smith | 0 | | John | Fritz | 1 | | Thomas…
Zombievirus
  • 177
  • 1
  • 2
  • 12
2
votes
2 answers

Merge two PSCustomObject tables into a single one with PowerShell

I want to use PowerShell to merge two tables into one. #Sample table $CarList1 = @() $CarList2 = @() $CarList1 = [PSCustomObject]@{ "Brand" = "Audi"; "Model" = "A8"; "Color" = "Red"; "ManufactureDate" =…
uragus
  • 67
  • 5
2
votes
1 answer

PowerShell, PSCustomObject, array format issue

I am trying to create array made by PSCustomObject elements, but having some issues with it. Here is the simplified example of the code I have: $FineData = @() foreach ($Session in $Sessions) { $Job = Get-VBRTaskSession -Session $Session…
Alexey
  • 61
  • 4
2
votes
1 answer

How to make an in-variable change to objects that isn't slow with PSCustomObjects?

I have two tables as pscustomobjects and I tried doing the equivalent of a SQL join to add some properties back into the primary object that I need to read from. The issue is that my code below ran on an object collection for 5 hours with about…
2
votes
4 answers

Powershell Pipeline - return a new Object, that was created within pipline

I keep running into the same problem again, and i have my default way of handling it, but it keeps bugging me. Isn't there any better way? So basicly i have a pipline running, do stuff within the pipline, and want to return a Key/Value Pair from…
Evilcat
  • 388
  • 3
  • 9
2
votes
1 answer

The server has returned the following error: invalid enumeration context. Get-ADComputer

I have this portion of code that is throwing an invalid enumeration context error. $ADComputers1 = (get-adcomputer -Filter {enabled -eq $true} -ResultPageSize 500 -ResultSetSize $null -Properties instanceType, IPv4Address, IPv6Address,…
kutulo
  • 39
  • 5
2
votes
1 answer

PowerShell - JSON/PsCustomObject - Why does my array get flattened into a single object?

The owners key in my output (see OutputFile) I'm expecting as a line separated array, but it's outputting as a single-line space separated object/string Script: function Add-ApplicationOwner { param ( [string] $App, [object]…
swtto
  • 125
  • 2
  • 12
2
votes
2 answers

Powershell Split PSCustomObject if Property has multiple values while duplicating other values

My current PSCustomObject Invoice Auction Item ID Date 18585208 X8C3E5651 K5W6L07795 Feb 18, 2021 99457377 U9V7E3466 J2X1D40777 Feb 14, 2022 91833688 D2A7O0545 T7Z6Y74627,H3B4U81837 Feb 23,…
2
votes
1 answer

foreach ($key in $map.keys) not behaving as expected

I'm trying to iterate over each key of a hash map, and for each key, look it's value up in 3 different maps, assigning to a psCustomObject. For some reason, after just going through the foreach once, the resultsCase looks like this, and the length…
Michele
  • 3,617
  • 12
  • 47
  • 81
1
2
3
10 11