1

I would like to add a custom object with Properties as below to a powershell array. I have tried various options but unable to get the proper syntax of such an object addition to an array. Iam using Powershell V2. Please help.

PS C:\Windows\system32> $executemultiplerequest | Get-member


   TypeName: Microsoft.Xrm.Sdk.Messages.ExecuteMultipleRequest

Name          MemberType            Definition
----          ----------            ----------
Equals        Method                bool Equals(System.Object obj)
GetHashCode   Method                int GetHashCode()
GetType       Method                type GetType()
ToString      Method                string ToString()
Item          ParameterizedProperty System.Object Item(string parameterName) {get;set;}
ExtensionData Property              System.Runtime.Serialization.ExtensionDataObject ExtensionData {get;set;}
Parameters    Property              Microsoft.Xrm.Sdk.ParameterCollection Parameters {get;set;}
RequestId     Property              System.Nullable`1[[System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, Publ...
RequestName   Property              System.String RequestName {get;set;}
Requests      Property              Microsoft.Xrm.Sdk.OrganizationRequestCollection Requests {get;set;}
Settings      Property              Microsoft.Xrm.Sdk.ExecuteMultipleSettings Settings {get;set;}

Adding the Options i have tried :

Here are the samples that i have tried with :

$item = New-Object System.Object
$item | Add-Member -MemberType Method -Name Equals $executemultiplerequest.Equals -MemberType Property $executemultiplerequest.ExtensionData
$array += item

I received an error even before i went onto store into an array. The error was received on the Add-Member line as :

Add-Member : Cannot add a member with type "Method". Specify a different type for the MemberTypes parameter. 
6
  • 1
    I have tried various options --> What did you try? Can you show us some code? Commented Jun 10, 2016 at 5:46
  • Here are the samples that i have tried with : $item = New-Object System.Object $item | Add-Member -MemberType Method -Name Equals $executemultiplerequest.Equals $array += item $item = New-Object System.Object $item | Add-Member -MemberType Property $executemultiplerequest.ExtensionData $array += item Commented Jun 10, 2016 at 5:50
  • Can you please edit your question and add them? It's hard to read in the comments ;) Commented Jun 10, 2016 at 5:55
  • 1
    Updated the question to reflect an option i have tried with... Commented Jun 10, 2016 at 5:57
  • Is the last line really that what you tried? Hint: item instead of $item Commented Jun 10, 2016 at 6:09

1 Answer 1

1

i am not sure about the types you are using but if you want to

$item = New-Object psobject
$item | Add-Member -MemberType NoteProperty -Name RequestName -Value 'some string here'
$item | Add-Member -MemberType ScriptMethod -Name Multiply -Value {param($x,$y);$x * $y }
$item | Add-Member -MemberType ScriptProperty -Name RequestName1 -Value { Get-Service -Name BITS }

read more about Add-member here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.