Questions tagged [pscustomobject]

0

votes
0

answer
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

votes
1

answer
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

votes
1

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

votes
2

answer
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

votes
1

answer
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

votes
1

answer
44

Views

PowerShell, How to provide a pipe variable?

This is a high level question as the details might not be precise, as I'm not in my office but home. I have a function that accept variables through pipe: get-csv | myfunc The pipe source is the fields from a .csv file. How to define a variables and pipe into myfunc()? Would HashTable be good? $my...
xpt
1

votes
2

answer
860

Views

Powershell Custom object - not passing foreach variable

I'm trying to create a custom object based on server names from a text file. The script I have goes and imports the txt file into a Variable. Then runs a foreach server in the servers variable to create the custom object. I would like to be able to output the object's properties as a table that doe...
eMpy
4

votes
1

answer
97

Views

ExpandProperty - objects missing from pipeline

I have some objects in a pipeline, something like this: $arr1 = @( (New-Object -TypeName psobject -Property @{'objname'='obj1';[email protected]((new-object -typename psobject -Property @{'pname'='prop1';'val'=11;}),(new-object -typename psobject -Property @{'pname'='prop2';'val'='xx';}))}), (New-Object -Type...
Adam Luniewski
3

votes
1

answer
4k

Views

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 PSObject $props I now have a custom object with som...
Joost
2

votes
2

answer
2k

Views

Why are script properties lost when passing pscustomobject to start-job script block?

On windows XP x64 (and I assume win2k3) powershell 2.0, passing an arraylist of pscustomobjects to start-job as argumentlist parameter passes the object in but scriptproperties just disappear from the object (confirmed by get-member). Note properties of the pscustomobject do return just fine Anyone...
JorgeSandoval
28

votes
4

answer
47.1k

Views

How to get Select-Object to return a raw type (e.g. String) rather than PSCustomObject?

The following code gives me an array of PSCustomObjects, how can I get it to return an array of Strings? $files = Get-ChildItem $directory -Recurse | Select-Object FullName | Where-Object {!($_.psiscontainer)} (As a secondary question, what's the psiscontainer part for? I copied that from an example...
Mark Ingram
6

votes
1

answer
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...
icnivad
6

votes
2

answer
8.3k

Views

Column ordering when exporting to CSV in PowerShell - controlling the property enumeration order of custom objects created from hashtables

I'm writing a script in Powershell that exports all securitygroups and their members from Active Directory. Now I want to format the output of the .csv. The Code: $Groups = Get-ADGroup -Properties * -Filter * -SearchBase 'OU=SERVICES,DC=XXXXXX,DC=XXXXX' $Table = @() $Record = @{ 'Group Name' = '' '...
Svekke
13

votes
2

answer
4.4k

Views

PowerShell type accelerators: PSObject vs PSCustomObject

In PowerShell v3.0 PSCustomObject was introduced. It's like PSObject, but better. Among other improvements (e.g. property order being preserved), creating object from hashtable is simplified: [PSCustomObject]@{one=1; two=2;} Now it seems obvious that this statement: [System.Management.Automation.PSC...
Adam Luniewski
1

votes
2

answer
359

Views

Powershell create object from multiple files

I am making a PSObject from a json file bar.json { 'derp': { 'buzz': 42 }, 'woot': { 'toot': 9000 } } I can make a PSCustomObject form the json using ConvertFrom-Json $foo = Get-Content .\bar.json -Raw |ConvertFrom-Json $foo.gettype() IsPublic IsSerial Name Bas...
spuder
2

votes
1

answer
767

Views

Change values of an array of pscustomobject's with a for-loop

I have tried to create a array of custom objects (pscustomobject) and now i tried to change some values of the different custom objects with an for-loop. But it doesn't seem to work. Here is what i tried: $obj = @([pscustomobject]@{value=0;type='D';used=$false}) $arr1 = @($obj) * 10 for($v = 0; $v -...
frupfrup
2

votes
2

answer
2.5k

Views

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 of my values inserted on one row for each column ins...
Jumpman
38

votes
7

answer
92.1k

Views

Powershell: How to initialize array of custom objects?

First, as this leads to my question, I'll start by noting that I've worked with XML a fair bit in Powershell, and like how I can read data from xml files, quickly, into arrays of custom objects. For example, if I had the following XML file: something about him something about her something else And...
SteveDJ
1

votes
3

answer
854

Views

How do I add a System.Collections.ArrayList to a PowerShell custom object?

My goal is to create a custom data object that has two discrete variables (fooName and fooUrl) and a list of fooChildren, each list item having two discrete variables variables childAge and childName. Currently, I have this: $fooCollection = [PSCustomObject] @{fooName=''; fooUrl=''; fooChildrenList=...
Nova Sys Eng
2

votes
2

answer
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
56

votes
5

answer
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...
alphadev
1

votes
2

answer
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
2

votes
1

answer
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
2

votes
3

answer
401

Views

How to avoid leading white space addition with string formatting?

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
2

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]...
0

votes
1

answer
702

Views

Convert array of custom objects to HTML

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...
Sum1sAdmin