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

dynamically creating key/value of an object and exporting to CSV

After getting a search result from an LDAP Server, i need to create a pscustomobject dynamically. The Problem here is that some of the attributes are not set for all users. this is why i cannot create the pscustomobject the traditional way. Name =…
Zombievirus
  • 177
  • 1
  • 2
  • 12
0
votes
0 answers

Error handling with Get-wmiObject for pscustomobject in Powershell

Building this script I want to have the output stored in a TXT file and leave the details blank which cannot be found. It works for the Get-ADuser function but not for Get-wmiObject. I've got my PC names and user ids from a CSV file but sometimes a…
Toon
  • 29
  • 8
0
votes
1 answer

PowerShell --- Get Unique Values from PSCustomObject Array

[{ "UserDisplayName": "Test1 User1", "UserPrincipalName": "TestUser1@test.com", "License": "Basic", "UserEmail": "TestUser1@test.com", }, { "UserDisplayName": "Test1 User1", "UserPrincipalName": "TestUser1@test.com", …
Satya
  • 25
  • 5
0
votes
0 answers

Calculate number of pixels for each resolution on each line, and sorting them by size

I am writing a skin for Rainmeter, that can change resolutions of a monitor. The Powershell measure in my Rainmeter skin, uses a command line utility to retrieve a list of possible resolutions. But I'm having trouble sorting the list (Largest to…
NotBot
  • 1
0
votes
2 answers

Limit the time of use of a .exe with POWERSHELL

I've been looking during 2 days for a sotfware which allows me to limit the time I play(or use any program) and I found nothing usefull so I decided to put my coding cape back since 6 years ago and program it myself. A friend recommended me…
0
votes
1 answer

pscustomobject: delete unique, keep duplicates

I have written a script that extracts all the duplicate emails in a WS2012 AD. The Script has all the Users with duplicate emails in a pscustomobject Now what i want to achieve is to delete the first unique email entry and keep all the duplicate…
Zombievirus
  • 177
  • 1
  • 2
  • 12
0
votes
1 answer

Adding JSON content to PSCustomObject - The property cannot be found on this object

Quite new to objects in PS. I'm trying to create pscustomobject, adding JSON contents to it via ConvertFrom-JSON and then I'm trying to get contents from another JSON to be set on one of the properties ( nested hierarchy) $combinedObject=@() $props…
Chris
  • 23
  • 6
0
votes
0 answers

Getting the length of data in a PScustomobject while querying AD

I am trying to get a pscustomobject to sort by Canonicalname length, but in order to do this I need the length of each CanonicalName within the PScustomobject. The Canonicalnamelen is where the length needs to be stored and sorted. The reason I need…
0
votes
2 answers

Convert Output or Object in Array to Table Powershell

I created a custom object $customsa = New-Object -TypeName psobject $customsa | Add-Member -MemberType NoteProperty -Name Name -Value (Get-AzStorageAccount).StorageAccountName $customsa | Add-Member -MemberType NoteProperty -Name Tier -Value…
0
votes
2 answers

How to get the name of a PsCustomObject?

I have a Powershell-script which includes a lot of PsCustomObjects like this (names do not have a specific pattern): $myObject1 = [PSCustomObject]@{ Name = 'Kevin' State = 'Texas' } $myObject2 = [PSCustomObject]@{ Name =…
Carsten
  • 1,612
  • 14
  • 21
0
votes
1 answer

Questions about Powershell objects, property names, multiple property values with the same name and dot sourcing issues

There is code at the bottom of this to help make it easy to reproduce what I'm asking in my questions. My questions are: $parentObject.Children.Children.Andrew."Birthday Info" --- is there a programmatic way to know to need quotes and add…
Bbb
  • 517
  • 6
  • 27
0
votes
1 answer

PSCustomObject - use contains filter on array

i am trying to figure out how i can search a value in an array that is in a pscustomobject. $global:RuleSet+= [pscustomobject][ordered]@{ RuName="NSMS" ; Agent=("ABC", …
pyte
  • 41
  • 1
  • 5
0
votes
1 answer

Powershell replace values in target.json with values from source.json

I have a big target json file (parameters_general.json) where all common settings for a deployment are set. For each tier I have another json file (ex: parameters_dev.json, parameters_test.json, ....) Settings set in one needs tobe added to the…
njefsky
  • 327
  • 2
  • 5
0
votes
1 answer

PowerShell Multiple Arrays into a Custom HTML Table

Good Morning all. I’m working on a script that updates a set of applications and I’m trying to make a HTML table for verification purposes. This comment is my…
Fitzgery
  • 558
  • 5
  • 14
0
votes
1 answer

Powershell creating pscustomobject object

I need help on something I really can't figure out. I have a file containing loads of these ID's I need to create a json payload in powershell to look like this containing each of these ID's { "assetIds": [ …
Hein
  • 25
  • 4