Questions tagged [psobject]

PSObject is used for object encapsulation in PowerShell and is used for a consistent view in its environment.

174 questions
1
vote
1 answer

PowerShell, unexpected different results depending upon what is removed from a JSON structure

Hoping that someone might be able to explain why the first removal does not affect the first variable, but the second removal does affect the first variable, please. Thank you. $X = @' { "$schema": "myschema", "parameters": { …
sdo
  • 13
  • 6
1
vote
1 answer

Addings Child to PSObject after Creation

When using Powershell the Add-Member function can be used for manipulation of the object tree. Following Function should read a CSV with Customers and their corresponding domain names and build a object tree as follows : Customer1--- some…
Wolfgang
  • 11
  • 2
1
vote
3 answers

How to import an array of PSObjects from a text file?

This is simple enough: PS C:\Users\saunders\Desktop\data> PS C:\Users\saunders\Desktop\data> ls .\test.csv Directory: C:\Users\saunders\Desktop\data Mode LastWriteTime Length Name ---- ------------- …
1
vote
1 answer

Is there a way to tell if a PSObject has children?

I am working to build a way to iterate through all the key value pairs of a PSObject that was created by using ConvertFrom-Json. To do this, I need a way to know if a given PSObject has one or more children. So, given the following JSON: { …
Vaccano
  • 78,325
  • 149
  • 468
  • 850
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: remove value from property by its value

There is a JSON like: { a: { a1 : { a11:{}; a12:{}; a13:{};}; a2 : {some other values}; } b: { b1: {another values} } } so then I converted it using powershell with command and put it into a variable…
Kate
  • 33
  • 4
1
vote
1 answer

Powershell getting nested values: Can you use ConvertFrom-Json for nested Values

I have a json file, simplified version of it looks like this: { "Location": "EU", "Country": { "City": "xxx", "Town": "xxx" }, "Transport": { "Train": "xxx" } } I have run the ConvertFrom-Json command to convert to…
polo
  • 155
  • 4
  • 11
1
vote
1 answer

Return the "Name" of an object that has a specific "Value" in PSObject

I have converted a JSON file to a PSObject using: $json = Get-Content $filepath -Raw | ConvertFrom-Json An example of what is now in the PSObject: Value : Production MemberType : NoteProperty IsSettable : True IsGettable :…
polo
  • 155
  • 4
  • 11
1
vote
2 answers

How can I add child objects to a PsObject?

Is this the correct way to have a PsObject as a Property of a parent PsObject? This seems somewhat cumbersome to be the correct way and I can't dot source (see pictures at the bottom) the child PsObject's properties either. $function1.Params |…
Bbb
  • 517
  • 6
  • 27
1
vote
1 answer

Exporting Nested Json Values to CSV using powershell

I have been trying to loop through a list of .json config files to pull out 'name','entity_id','contact_info','sp_endpoint'. I have been trying to take the following code block, and dump it into a csv that lists each of the values in a column, and…
Ben S
  • 29
  • 4
1
vote
1 answer

Powershell - Hashtable collection in new PSObject

I'm started a query for our infrastructure to see how SNMP Service is configured on the servers. I managed to find a function that would extract just the relevant keys and values (without the PS* properties) from the 3 Registry paths…
1
vote
1 answer

Powershell Objects Sorting On Property - Descending - Not working

I am sorting the contents of the a text file as below APPLE|FINAL|20220122065900|0 APPLLE|PRE|20220122061500|0 MANGO|PRE|20220126113400|0 MANGO|PRE|20220125102200|0 MANGO|ASSYN|20220125102200|0 $file = Get-Content…
Geo V
  • 121
  • 1
  • 10
1
vote
3 answers

powershell psobject showing as string instead of psobject, how to convert back to psobject

I have the following variable $Obj set to the following string value: $Obj = '@{Version=1; Name=a;}' How do I convert this value from a string into a custom psobject? I would like to be able to call $Obj.Version and get the value 1. Currently this…
satoukum
  • 1,188
  • 1
  • 21
  • 31
1
vote
1 answer

PNPUtil retrieve each driver and add to array with PSObject

Using Powershell I retrieve all third party drivers installed using: $PNPDrivers = PNPUtil /Enum-Drivers The format of the information retrieved are as followed: Microsoft PnP Utility Published Name: oem19.inf Original Name: …
1
vote
2 answers

Powershell PSObject calculated property based on another property

I'm creating an array of PSObjects with calculated properties. I need one property that is calculated based on another property of the same object. How do I do that? Example - let's say I have array of strings like "a_1", "b_2", "c_3" etc. and I…
miguello
  • 544
  • 5
  • 15