# Questions tagged [pscustomobject]

26 questions

0

3

Views

### Unable to format json output to nested-json in powershell

I have a powershell json output in this format. { 'Name': 'web-app', 'BuildingBlock': 'create-web-app', 'TemplateName': 'qa-bb-create-web-app-V1.1.1', 'TemplateID': 1809 }, { 'Name': 'web-app', 'BuildingBlock': 'destroy-web-app', 'TemplateName': 'qa-bb-destroy-web-app-V1.1.1', 'TemplateID':...
B S

1

115

Views

### Powershell Object not being piped through to Functions

I have two functions one creates a custom object which once done is piped to the next function. The problem is that the second function is not receiving my object correctly. Instead of using the pipeline I have tried setting a variable and then piping that variable to the function. Below are the two...
APJ

1

369

Views

### Name property in ConvertTo-XML

I've the following XML Output: MyCustomerName Integration false I generate this code by: $customerInformation = [PSCustomObject]@{ CustomerName =$CustomerName; Environment = $Environment; isVdi =$isVdi; } What I would love is to give the tag that is around the object a name. For example:...
Twinfriends

2

71

Views

### Trying to add PSCustomObjects to an ArrayList on a remote machine

I have some experience with PowerShell, and usually Google or searching forums like these yields the answers when I have questions - but not this time. I'm trying to collect the number of .log files in a directory on a remote server, then I'd like to store the location (drive letter and folder path)...
Shaurya R

1

4.5k

Views

### Using a Powershell noteproperty as a text string in a variable

I've used Invoke-Restmethod to download some data, which Powershell stores in a PSCustomObject, in a property called data. I need to use the value of one of the items in the returned data as a variable for another command. I have managed to select-object -expand my way down to the following output f...

1

44

Views

1

4k

Views

Mark Ingram

1

10.2k

Views

### Powershell Custom Objects: How To Acess NoteProperty of collected result

Reading through an Article about custom Objects: http://technet.microsoft.com/en-us/library/ff730946.aspx I wonder why i get a result for the individual entry: e.g $objAverage.Name while by$colAverages.Name nothing is returened. Although with Get-Member both show the [System.Object] NoteProperty N...

2

8.3k

Views

Nova Sys Eng

2

2.5k

Views

### 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 $computers) {$file = $computer +'.txt'$a = import-...
fenster

5

42k

Views

### PSCustomObject to Hashtable

What is the easiest way to convert a PSCustomObject to a Hashtable? It displays just like one with the splat operator, curly braces and what appear to be key value pairs. When I try to cast it to [Hashtable] it doesn't work. I also tried .toString() and the assigned variable says its a string but di...

2

86

Views

### Export data in the order it was added - PowerShell Export-Csv

I have this code function get-data() { $rec=[PSCustomObject]@()$DLGP = '' | Select 'Name','Grade','Score' foreach($record in$data) { $DLGP.Name=$record.name $DLGP.Grade=$record.grade $DLGP.Score=$record.score $rec +=$DLGP } return $rec }$mydata=get-data $mydata | Export-Csv -Path$outputPath -N...
John Casablanca

1

31

Views

### Error adding second type that is dependent on the first [duplicate]

This question already has an answer here: How to access Add-Type defined type in other Add-Type type definition? 2 answers I'm writing a script using PowerShell which uses a custom object. But the tricky part is that this custom object uses another custom object as a property. I'm trying to do it w...
SokIsKedu

3

401

Views

I have a function which returns PSCustomObject, like this: Function Get-Data { # ... [PSCustomObject]@{ Url = $Url Id =$Id } } Later on, I call this function like this: $data = Get-Data And then I'd like to output formatted string including property values of that object. The closest result to what... Yan Sklyarenko votes 1 answer 450 Views ### PowerShell conditional statements while building PSCustomObject I want to perform a check of a variable's existence while creating a PSCustomObject. I have quite a few objects to query and gather data for into my new object so I don't want to duplicate the entire code block with an 'if' statement as I'm trying to be concise. [array]$newObject += [PSCustomObject]...

1

I am currently trying to feed some XML documents into a script and initialize them as [PSCustomObject]. The XML document needs to be broken into several objects and then added together. Here is my script: [xml]$CourseStructureIn = Get-Content .\Sample.xml$data = foreach ($Instances in$CourseStruct...