Questions tagged [psobject]

PSObject is used for object encapsulation in PowerShell and is used for a consistent view in its environment.

174 questions
4
votes
1 answer

ExpandProperty - objects missing from pipeline

I have some objects in a pipeline, something like this: $arr1 = @( (New-Object -TypeName psobject -Property @{'objname'='obj1';props=@((new-object -typename psobject -Property @{'pname'='prop1';'val'=11;}),(new-object -typename psobject…
AdamL
  • 12,421
  • 5
  • 50
  • 74
4
votes
1 answer

Without an explicit cast, an object gets wrapped in PSObject

When explicitly casting my new object (see the first line of code), my newly created EntityReference gets stored without being wrapped in a PSObject, and so serializing it works just fine: $entityRef1 = [Microsoft.Xrm.Sdk.EntityReference](new-object…
Leon Bouquiet
  • 4,159
  • 3
  • 25
  • 36
3
votes
1 answer

"The property cannot be found on this object. Verify that the property exists." Property definitely exists

I can't figure out why I am not able to change these variables. If I type them into the console in debug mode, then it prints the values. It is also strange how I am able to change the allowedRequestors variable on line 24, but not any of the…
Berty.
  • 43
  • 1
  • 1
  • 7
3
votes
1 answer

Explicitly return value in multiline calculated property in PowerShell

In PS, when using Select-Object, the -Property param "specifies the properties to select": The value of the Property parameter can be a new calculated property. To create a calculated, property, use a hash table. Valid keys are: Name:…
KyleMit
  • 30,350
  • 66
  • 462
  • 664
3
votes
1 answer

How to GET variables used in a specific BUILD in Azure Devops / TFS via api

From within both Build & Release pipelines in Azure Devops, I'm triggering other pipelines via api. I am trying to get my release pipeline to harvest custom variables that were discovered / used during the associated build. I'm able to get a list of…
nuprap
  • 385
  • 5
  • 22
3
votes
0 answers

powershell and .net object type different

i work with hyperv virtual machine and powershell and find really weird problem when i get the type of an object and then check for it (ex: String): PS > "str".gettype().fullname System.String PS > "str".gettype() -eq [System.String] True but when…
G.S
  • 392
  • 2
  • 13
3
votes
3 answers

Get PSObject array size or count

I create an array like this: $Array = @() $Item = New-Object PSObject $Item | Add-Member -Type NoteProperty -Name item1 -Value test $Item | Add-Member -Type NoteProperty -Name item2 -Value test $Array += $Item Now I want to add a check to…
Jonathan Rioux
  • 1,067
  • 2
  • 14
  • 30
3
votes
5 answers

How do I get the length of a PSCustom object?

The following is stored in powershell #Maintainer Note: The leftmost parameter must match the registry key name exactly e.g. 'DES 56' #For more information please check https://support.microsoft.com/en-us/kb/245030 $bannedCiphersJSON = @" { …
Ran Dom
  • 315
  • 5
  • 13
3
votes
1 answer

Is there any way to convert PSObject to string in C# while working with Powershell Api

I need to convert PSObject to String(). Is there any standard way available to do this task? Somehow powershell also does ToString() or spits out a readable stream on ISE console. I used PSSerializer.Serialize(PSObject) but it serializes…
Usman
  • 2,742
  • 4
  • 44
  • 82
3
votes
1 answer

New-Object add-member - cannot add a member - powershell

I have a problem :( I have many errors when I add New object with the same name of property which previously Object . "Add-Member : Cannot add a member with the name "ServerName" because a member with that name already exists. To overwrite the…
mino
  • 125
  • 2
  • 11
3
votes
3 answers

Search for a unknown property in an object based on its value

I am not sure how to do this with the usual suspects, namely Where-Object or Select-Object. Suppose I want to find the string "needle" in PSCustomObject $Object, and that object can have several Note properties, such as $Object.Haystack1,…
Bluz
  • 5,980
  • 11
  • 32
  • 40
3
votes
1 answer

Parse an PSObject instance to a C# object

How can I parse an PSObject instance to a C# POCO model entity? The PSObject instance is a dynamic object that contains these properties: @{Name=David; Diff=0.0268161397964839; File=Output.txt} I have C# POCO model that fits those fields. Is there…
Amir Katz
  • 1,027
  • 1
  • 10
  • 24
3
votes
2 answers

How do You Control Column Name Position When Creating CSV Exportable Object Arrays?

REFERENCE SCRIPTS: Script 1: $csvList = @() $csvList += New-Object PSObject -Property @{name="test1";accountname="testuser1";mail="user1@somewhere.com"} $csvList += New-Object PSObject -Property…
Colyn1337
  • 1,655
  • 2
  • 18
  • 27
3
votes
1 answer

Preventing PowerShell from wrapping value types in PSObjects

I have a .NET API that uses a lot of delegates. My API has a couple methods similar to the following: public static class MyClass { public static void DoSomethingWithString(Func myFunc) { string myStringValue =…
Phil
  • 6,561
  • 4
  • 44
  • 69
2
votes
1 answer

Import-CSV: add rows (members) to resulting object in foreach loop

I am trying to achieve the following with imported CSV Data in Powershell: the CSV has the following structure: | FirstName | LastName | Tier | | --------- | ------- | ---- | | George | Smith | 0 | | John | Fritz | 1 | | Thomas…
Zombievirus
  • 177
  • 1
  • 2
  • 12
1
2
3
11 12