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
3 answers

Using ref in powershell to return values from function

I've function DoWork which creates an object and keeps it in $AllMailboxes variable. Then within that function I execute another function ProcessEmail which is supposed to take $Mailbox out of $AllMailboxes and variable by ref, add couple of fields…
MadBoy
  • 10,824
  • 24
  • 95
  • 156
0
votes
1 answer

Scoping Custom Objects in Powershell

So I have a powershell issue that seems like it should be simple to resolve, but I am having trouble figuring it out myself. Take for instance the following program: $MyFavoriteAnimals = @() $Pets = "Cat","Dog","Fish","Bird" $Names =…
TroggleDorf
  • 410
  • 2
  • 8
  • 14
0
votes
1 answer

Arrays / CustomObjects

TL;DR: I'm trying to build an array with headers based off a condition, ideally looking like this. Name Value Status Element 1 Value 1 -- Element 2 Value 2 Action Required Element 3 Value 3 -- I've been trying it…
M O'Connell
  • 487
  • 5
  • 18
0
votes
2 answers

Trying to create a custom object list? hash? - Unsure

I'm trying trying to get two properties from two separate commands and add them to a variable to be able to further evaluate. I was told a custom object would work... Clear-Host Add-PSSnapin citrix* -ErrorAction SilentlyContinue $DRSrvs =…
0
votes
3 answers

Enumerating a PSCustomObject

Does anyone have know of a way to "break" open a hash table source from a custom object. There is no .getenumerrator on a custom object but I have this hashtable: @{0=0.05; 1024=0.050; 51200=0.050; 512000=0.050; 1024000=0.045; 5120000=0.037}. I am…
0
votes
2 answers

powershell: add pscustomobject to ArrayList, but all items goto 1st property

I just created a simple function "f" that adds an pscustomobject element into an arraylist, but when displaying it, result is not what I expected: $c=New-Object System.Collections.ArrayList($null) function f([string]$a1,[string]$a2) { …
Immanuel Kant
  • 517
  • 3
  • 8
0
votes
2 answers

Two arrays in a custom object

I'm trying to create a table with two arrays and I'm not sure whats the best way to make this happen. Here is my code $nomatchsam += $enabled.SamAccountName $nomatch10 += $enabled.extensionAttribute10 I'd like to take these arrays and do something…
JoeRod
  • 899
  • 8
  • 20
  • 30
0
votes
2 answers

Check if a property is a PSCustomObject in PowerShell v3

I have an array of PSCustomObject created with several properties on them. Some properties are ints, some strings, and others are what I surmise to be dictionary object (the objects are being returned from Invoke-RestMethod) Here's an example: >…
Ryan Taylor
  • 8,740
  • 15
  • 65
  • 98
0
votes
1 answer

Presentation of Data in Log Files

Hi just want to ask if it's possible that in PSCustomObject, I'll be having a duplicate array? Because I have to put a "|" but if did it twice, it won't accept unless I put a "space" on another "|" which is "| ". $customtable +=…
-1
votes
2 answers

Converting Output to CSV and Out-Grid

I have a file as below. I want it to convert it to CSV and want to have the out grid view of it for items Drives,Drive Type,Total Space, Current allocation and Remaining space only. PS C:\> echo $fileSys Storage system address: 127.0.0.1 Storage…
GURU SINGH
  • 149
  • 7
-1
votes
1 answer

How to output and format PsObject to multine text box in GUI

Im playing around with a GUI for WMI in powershell script. How do i format a PsObject to output in a multiline textbox so that each property of the PsObject is on its own line? This is for my own learning purposes - I know there are tools out…
Vynce82
  • 119
  • 3
  • 15
-1
votes
1 answer

Creating/Populating PSCustomObject in for loop From ADO.NET Data

I'm working with a bunch of Excel spreadsheets that have anywhere from 3 to 14 columns: Some really only have 3 columns Some have a number of hidden columns (e.g.: 5 are hidden 9 are visible) The rest are complete (all the data, no hidden columns…
JuliusPIV
  • 145
  • 1
  • 3
  • 11
-1
votes
2 answers

manipulate (add text) to CMDLET output

I've beat my head against the wall for a few days trying to figure this one out.. I'm trying to take the output of the following command, export it as a CSV with the hostname at the beginning of each line $reg1 = Get-ItemProperty…
bonneyt
  • 99
  • 1
  • 3
  • 9
-2
votes
2 answers

How to store the powershell pscustomobject output in a single variable

I have a script, where I get my output using pscustom object (the one with the value -eq 0.0) but is there a way to join $netscaler name+$cmponentname+$name in a single variable ? $Components = @("virtualserver", "services", "servicegroup",…
-2
votes
1 answer

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": …
B S
  • 1
  • 1
1 2 3
10
11