I am getting strange behaviour when passing an array object from my Main script into RunSpace code block.
I am trying to retrieve values using a Where-Object
statement within the RunSpace code block.
But produces an error relating to null method.
If I perform the same Where-Object
statement on the array before passed to runspace then it works?
For example if I perform the following on the array before its passed to RunSpace it works fine:
$ARRAY | Where-Object {$_.object -eq $Variable}).PropertyofwhatIWant.ToString()
If I pass this array to runspace and perform the same thing it fails with:
You cannot call a method on a null-valued expression. At line:25 char:13 + $strSourceGivenName = ($arr_Src_Users1 | Where-Object {$_.objectsid ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
I have compared both array objects and they have the exact same properties?
There is no difference of ARRAY and ARRAY1 when checking Get-Member
?
What is going on?
Module : CommonLanguageRuntimeLibrary Assembly : mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 TypeHandle : System.RuntimeTypeHandle DeclaringMethod : BaseType : System.Array UnderlyingSystemType : System.Object[] FullName : System.Object[] AssemblyQualifiedName : System.Object[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Namespace : System GUID : 00000000-0000-0000-0000-000000000000 IsEnum : False GenericParameterAttributes : IsSecurityCritical : False IsSecuritySafeCritical : False IsSecurityTransparent : True IsGenericTypeDefinition : False IsGenericParameter : False GenericParameterPosition : IsGenericType : False IsConstructedGenericType : False ContainsGenericParameters : False StructLayoutAttribute : Name : Object[] MemberType : TypeInfo DeclaringType : ReflectedType : MetadataToken : 33554432 GenericTypeParameters : {} DeclaredConstructors : {Void .ctor(Int32)} DeclaredEvents : {} DeclaredFields : {} DeclaredMembers : {Void Set(Int32, System.Object), System.Object& Address(Int32), System.Object Get(Int32), Void .ctor(Int32)} DeclaredMethods : {Void Set(Int32, System.Object), System.Object& Address(Int32), System.Object Get(Int32)} DeclaredNestedTypes : {} DeclaredProperties : {} ImplementedInterfaces : {System.ICloneable, System.Collections.IList, System.Collections.ICollection, System.Collections.IEnumerable...} TypeInitializer : IsNested : False Attributes : AutoLayout, AnsiClass, Class, Public, Sealed, Serializable IsVisible : True IsNotPublic : False IsPublic : True IsNestedPublic : False IsNestedPrivate : False IsNestedFamily : False IsNestedAssembly : False IsNestedFamANDAssem : False IsNestedFamORAssem : False IsAutoLayout : True IsLayoutSequential : False IsExplicitLayout : False IsClass : True IsInterface : False IsValueType : False IsAbstract : False IsSealed : True IsSpecialName : False IsImport : False IsSerializable : True IsAnsiClass : True IsUnicodeClass : False IsAutoClass : False IsArray : True IsByRef : False IsPointer : False IsPrimitive : False IsCOMObject : False HasElementType : True IsContextful : False IsMarshalByRef : False GenericTypeArguments : {} CustomAttributes : {[System.SerializableAttribute()]}