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
1
vote
1 answer

How to create a reference to a child item in XML using PSCustomObject

I have a XML file, generated by WinServer 2019 (GPO export). I'd like to create a reference to a child item, to the one, which contains the name of the AD groups: SeNetworkLogonRight
szaboors
  • 15
  • 4
1
vote
1 answer

How to use PS calculated properties to collate data into a cell?

I'm stumped on this one. I have a PS custom object with strings only and I want to build a report where I'm outputting strings of data into a new pipeline output object. $myObjectTable | Select-Object @{ n = "OldData"; e = { $_ |…
1
vote
2 answers

Append 2 pscustomobjects into 1

I am new to powershell. I have 2 pscustomobjects in powershell script. I want to bring them together as one and output into csv. The problem is there is no key column to match in both, just want to append them together. I was able to use the…
1
vote
1 answer

Powershell problem with order of execution in script

I'm having a problem with unexpected order of things being run and returned in the below Powershell script. The Write-ArrayToTable function is to output the data in the arrays in a pretty table-like fashion via custom object. The problem is when I…
xeric080
  • 99
  • 8
1
vote
1 answer

Powershell: converto-html separate values onto new lines

I'm building a script that will create an html report containing a table with multiple values in each Column Row (e.g. given cell may have 1 or more values). I'm building my output variable like this (assume there is a bunch of script before that…
Jim842
  • 23
  • 2
1
vote
1 answer

Alter object value upon assignment to PSCustomObject

I'm creating a log of attempted posts to an API. The API key is stored in a simple hash table and passed via Invoke-WebRequest: $headers = @{ 'x-api-key' = 'ABC123DEF456GHI789' } Try { [Net.ServicePointManager]::SecurityProtocol = 'tls12,…
Tony
  • 2,658
  • 2
  • 31
  • 46
1
vote
1 answer

powershell convert a list of csv values (PSCustomObject) to integer

i read a csv file into a variable using Import-CSV. Now when I try to print a list of all values of a certain property, I can see through GetType() that these are not Integer values but rather "PSCustomObjects". How can i convert all of these values…
J.Doe
  • 125
  • 1
  • 1
  • 10
1
vote
1 answer

How can I access Powershell PSCustomObject properties?

I'm processing through Powershell script some API result processing. API data (json) come from this : $tree = Invoke-WebRequest -Uri "xxxxxxxxmonURLxxxxxxxxxx/130333" $children = ($tree.Content | ConvertFrom-Json).data.12345.children Then I loop…
Potemkin
  • 76
  • 9
1
vote
2 answers

Adding values from two arrays into a PSCustomObject

I am trying to combine values from two arrays into a table using a PSCustomObject. One array has the passwords and one array has the users. When I try to combine them in to a PSCustomObject array it only list the last value in the array, not a…
Sti4n
  • 13
  • 4
1
vote
1 answer

Powershell: Create multiple PSCustomObjects from 3 arrays with different length

It is a beginner question but after hours of hours trying, i still do not know, what is better than create 3 different forloops, or one with if-decisions: Example Code: $a = 1,2,3 $b = 5,6,7,8,9 $c = 4, 10 $test = [PSCustomObject]@{ A = $a …
Andy W.
  • 13
  • 2
1
vote
0 answers

Can not pull in the "value" component of the Key\Value pair into the CSV result set

The program disables the feature "internet Explorer 11 after looping through a list of servers and exports the results to a csv file with Server Names and the "state" of the Internet explorer as columns as shown below but value component does not…
Maks
  • 11
  • 2
1
vote
1 answer

pscustomobject multiple lines per row

I have some code so far, but would like it to result in a table with multiple lines for users per group. Currently, it creates a table like…
user10568257
1
vote
3 answers

PowerShell - print a JSON output with sorted array of objects?

How can I print a JSON output with sorted array of objects? My $result object must remain as it is, the order of "Good" or "Bad" doesn't matter, I'm trying to sort the objects in the arrays sorted by "count" property in ascending order. My…
Adela
  • 23
  • 4
1
vote
1 answer

PowerShell Add-Member ... odd behaviour?

Can anyone explain what appears to be odd behaviour when using Add-Member to add an attribute to a PSCustomObject object? For some reason, once you've added the member, the object is represented like a hashtable when displayed, even though it's…
Simon Catlin
  • 2,141
  • 1
  • 13
  • 15
1
vote
2 answers

PowerShell ArrayList converting to PSCustomObject when added as Property of another PSCustomObject inside another ArrayList

I am trying to create a PSCustomObject that has multiple properties that are ArrayLists containing PSCustomObjects. I Am adding the parent object to an ArrayList as well. The idea is to create a relationship that I can easily parse out to yml or…