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
0
votes
2 answers

Pscustomobject adding dynamic values

I am trying to read group membership of computers from a particular OU and write to a CSV file. The input criteria for the group membership is like if the computer is part of say "admin" and i need the csv file in the below…
Enigma
  • 123
  • 1
  • 13
0
votes
0 answers

Powershell Iterate through multidimensional array of hashtables to get nested values in the array deep in json structure

I need to combine values from 2 JSONs: If there is a match in alerts IDs, I need to create structure, that will take data from both jsons. I need to find out how to get to those properties nested in arrays deep in json like: entities (JSON2) and…
aster007
  • 335
  • 2
  • 13
0
votes
1 answer

Accessing unknown levels of PSCustomObject nested object

I'm getting a response from an API with unknown nested levels of properties, this is an example: affects_rating : True assets : {@{asset=xxxxxxxxxxxxx; identifier=; category=low; importance=0.0; is_ip=True}} details …
Bryan Arreola
  • 197
  • 1
  • 6
  • 22
0
votes
1 answer

Powershell Append PSCustomObject to nested PSCustomObject

My problem is that I have a remote API giving me a JSON with 10 levels deep nesting and I need to add another array/hashtable/PSCustomObject (whatever you want to call it) to one of them. The JSON looks like this: { "result": [ "modules":…
Peet
  • 1
  • 1
0
votes
1 answer

Exporting multiple PSCustomObject s to a single CSV

I have 2 PScustomObjects that i would like to combine into a single csv as follows: $Output1 = [PSCustomObject]@{ Timestamp1 = (Get-Date) InstanceName1 = $ProcessName1 Count1 = $Processes1.Count …
Milnik
  • 55
  • 1
  • 6
0
votes
1 answer

Powershell, how obtain a csv by column with a pscustomobject or ordered?

Being a beginner in Powershell, I have a problem that I can't solve. I get the average of different CSV files as a string with the following code: # recovery of the list of csv files present in the folder "folder_1". $files=(Get-ChildItem -path…
0
votes
1 answer

In PowerShell, why is my if statement returning the whole array rather than a single object?

I have a script that is suppose to Find which Scope the Hostname in. My PSCustomObject Location = $scope.name is getting the whole array of scopes rather than the match, as seen below. Asset : U1087 Location : {bdg-213, Vo213, 0V-Gen-DH,…
feelsgood
  • 135
  • 14
0
votes
1 answer

Powershell Clone Object ArrayList

I create a PSCustom Object with some Properties and add this to a Collection in short like $Collection = @() foreach ($item in $items) { $obj = New-Object PSCustomObject $obj | Add-Member -NotePropertyName Property1 -NotePropertyValue "" …
crdy
  • 43
  • 9
0
votes
1 answer

How do you use the default values on a PSCustomObject's ScriptMethod

I am trying to specify the value of the third parameter of the method, while still letting the second parameter in the method default. I was able to piece this together to get it working, but I was hoping someone else had a better…
Gregor y
  • 1,762
  • 15
  • 22
0
votes
1 answer

How can I use a PSCustomObject ScriptMethod on the pipeline

PSVersion: 5.1 DesiredWhat I wished would work $obj = [PSCustomObject]@{ PSTypeName = 'MyObject' con = 'local' } add-member -MemberType ScriptMethod -InputObject $obj -Name MyMethod -Value { …
Gregor y
  • 1,762
  • 15
  • 22
0
votes
1 answer

PowerShell - An weird issue related to convertfrom-string

So I am trying to get average lengths of the four seasons in the 21st century using PowerShell as a self-imposed programming challenge. My idea is to get values from a text file, create a [PSCustomObject] and assign values to its noteproperties each…
user14636788
0
votes
0 answers

PSCustomObject with pages - page limit set to 25

I use Invoke-RestMethod to retrieve metadata about a bunch of documents in a folder via a REST API. While the method returns all the data in a PSCustomObject, I can't figure out how to access all of it. The custom object has the properties "page",…
0
votes
1 answer

Converting PSCustomObject to Hashtable

I'm having some problems converting some data from a json payload. The closest I've gotten is converting it to a PSCustomObject like below; Fields ------ {@{short=true; title=Status; value=Status text.}, @{short=true; title=Type; value=Type text.},…
FlashBI
  • 3
  • 2
0
votes
2 answers

Add Values into Nested Objects in PowerShell like you can in Python

I am looking use PowerShell to output some JSON that looks like this for use with a Python script: { "run_date": "2020-08-27", "total_queries": 4, "number_results": 3, "number_warnings": 1, "number_errors": 5, "build_url":…
takeoff127
  • 43
  • 5
0
votes
1 answer

PSCustomObject out-gridview incorrect formating

I am having an issue with the output from one property as a comma separated value instead of a list in the out-gridview. Is there a way to have a value be added to the output as a list instead of a single line? .'C:\Program Files\Microsoft\Exchange…
vnavna
  • 63
  • 1
  • 1
  • 5