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

Powershell scripting custom object

below data set is stored is text file and first is server name, second one is date and 3rd one is the patch histroy. WSUSCL02-2012 Monday, August 10, 2020 5:03:08 PM X Status KB Size Title …
prabhat
  • 1
  • 3
0
votes
1 answer

Is there a way to get sorted PSCustomObjects after using Compare-Object on two .JSON files?

I am comparing .JSON files, using Compare-Object like this: # Compare two files $BLF = (Get-Content -Path C:\Users\...\Documents\Android1.json) $CLF = (Get-Content -Path C:\Users\...\Documents\Android2.json) $a = Compare-Object -ReferenceObject…
esr
  • 1
0
votes
2 answers

Powershell PSCustomObject Extracting values

When creating and working with PSCustomObjects which result in a NoteProperty member with a 'Definition' (as shown below), is there any easy, programmatic way to select the values from the definition fields without resorting to splitting the…
Indrid
  • 962
  • 4
  • 25
  • 39
0
votes
1 answer

Combining 2 cmdlets for one result/output using pscustomobject

Basically what i'm trying to achieve here is an output with 4 column/list (in this case i'm exporting as a text) Get-MailboxPermission gives me a property of identity, user, accessrights but it doesn't give me a property of "Manager". I need to…
RENSOL
  • 1
0
votes
1 answer

Export-csv not writing content in file when inputting info from script running Invoke-Command for Test-NetConnection

First of all thank you for reading. I am new to Powershell so please forgive my ignorance. Also, this is my first time posting here. Before I had this and it was working, however, it was crazy slow. Here is the initial script: $RemoteComputers =…
Kody
  • 16
  • 3
0
votes
2 answers

Unable to outputting PSCustomObject

I input a collection then I have have to loop through to make the customobject. The Names in the object are all unique. I am hoping to have PSCustomObject in a variable that I can use later. Function Get-PSCustomObjectAsOutputType { $services…
Aaron
  • 563
  • 3
  • 13
0
votes
1 answer

Merging two CSV files in Powershell but some output entries are doubled with missing data

I am currently in the process of setting up a file upload for a work project. The uploaded file should contain all items with the necessary data and all variations (eg. size or length). The problem is, I can't export the variation data in the same…
Eisman333
  • 5
  • 3
0
votes
1 answer

In powershell, how to test in an array already contains an object with all the same properties?

I want to avoid inserting duplicates into an array in powershell. Trying to use -notcontains doesn't seem to work with a PSCUstomObject array. Here's a code sample $x = [PSCustomObject]@{ foo = 111 bar = 222 } $y = [PSCustomObject]@{ …
PBG
  • 8,944
  • 7
  • 34
  • 48
0
votes
1 answer

Can a PS Custom Object be created from a variable?

I have a 100 column table in sql server and I want to make it so not all of the columns need to be passed in the file to load. I have assigned column names in a table that then compares the columns in a hash table to find matching columns. I then…
0
votes
1 answer

Adding a timestamp in a JSON body

I am quite new to powershell and not used to it yet. I am trying to remote some of my servers in RealTime. For that I use a RestAPI that send me data on a JSON format (that Powershell automatically convert to a PSCustomObject). The thing is that…
Lord Djaz
  • 69
  • 1
  • 1
  • 7
0
votes
1 answer

Format of the Export-Csv in Powershell - unexpected column order

I'm trying to export an array of objects to a .csv file, what do I need to do to put everything in the right column with header of a property name. I've tried selecting properties by select to pipeline $groups = Get-MsolGroup -All $results =…
0
votes
3 answers

Parse log file and turn it into a custom object

The log file contains: ===== SMTP_server_not_set_up @PANEL SMTP server not set up. Contact system administrator. @PAGECNT 381 @SCANADFCNT 0 @DATETIME 2019-08-29T10:05:51-0400 @UPTIME 0:00:23 @CODELVL Base MSNGM.053.023 Engine GM.052.E015 Panel…
Rakha
  • 1,874
  • 3
  • 26
  • 60
0
votes
1 answer

Create table with different output

Write-Host "Errors" -BackgroundColor Red $Error.Clear() {Some 1200 lines code} I want to create a table after code excution with two columns: "Error" and "Line", if there were any errors in code above. But I failed using PSCustomObject (PSObject).…
farag
  • 325
  • 1
  • 4
  • 20
0
votes
1 answer

Converting pscustomobject into Json format

I have sample Json format that I am currently trying to code using powershell and convert it to Json format using PScustomobject, however I am having a hard time since the DBdetails count will depend on an array that I am retrieving. What is wrong…
0
votes
1 answer

How to filter pscustomobject on the basis of multiple columns

I have a pscustomobject which i want to remove items from. Every entry contains 3 values separated by a semicolon. The first one is a code, the second one a date, and the third one a description. I would like to make either a new pscustomobject…
Ivosein
  • 53
  • 5