将数组对象从我的 Main 脚本传递到 RunSpace 代码块时,我遇到了奇怪的行为。我正在尝试使用Where-Object
RunSpace 代码块中的语句检索值。但会产生与 null 方法相关的错误。
如果我在传递给运行空间之前对数组执行相同的Where-Object
语句,那么它可以工作吗?
例如,如果我在将数组传递给 RunSpace 之前对数组执行以下操作,则它可以正常工作:
$ARRAY | Where-Object {$_.object -eq $Variable}).PropertyofwhatIWant.ToString()
如果我将此数组传递给运行空间并执行相同的操作,则会失败:
您不能在空值表达式上调用方法。 在行:25 字符:13 + $strSourceGivenName = ($arr_Src_Users1 | Where-Object {$_.objectsid ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
我已经比较了两个数组对象并且它们具有完全相同的属性?检查时ARRAY和ARRAY1没有区别Get-Member
吗?到底是怎么回事?
模块:CommonLanguageRuntimeLibrary 程序集:mscorlib,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089 类型句柄:System.RuntimeTypeHandle 声明方法: 基本类型:System.Array 底层系统类型:System.Object[] 全名:System.Object[] AssemblyQualifiedName:System.Object[],mscorlib,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089 命名空间:系统 GUID:00000000-0000-0000-0000-000000000000 IsEnum : 假 通用参数属性: IsSecurityCritical : 假 IsSecuritySafeCritical : 假 IsSecurityTransparent:真 IsGenericTypeDefinition:假 IsGenericParameter : 假 通用参数位置: IsGenericType : 假 IsConstructedGenericType:假 包含通用参数:假 结构布局属性: 名称:对象[] 成员类型:类型信息 声明类型: 反射类型: 元数据令牌:33554432 通用类型参数:{} 声明的构造函数:{Void .ctor(Int32)} 声明事件:{} 声明字段:{} 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& 地址(Int32), System.Object Get(Int32)} 声明的嵌套类型:{} 声明的属性:{} 实现接口:{System.ICloneable,System.Collections.IList,System.Collections.ICollection,System.Collections.IEnumerable...} 类型初始化器: 嵌套:错误 属性:AutoLayout、AnsiClass、Class、Public、Sealed、Serializable IsVisible : 真 IsNotPublic : 假 IsPublic : 真 IsNestedPublic : 假 IsNestedPrivate : 假 IsNestedFamily : 假 IsNestedAssembly:错误 IsNestedFamANDAssem:错误 IsNestedFamORAssem : 错误 IsAutoLayout : 真 IsLayoutSequential : 假 IsExplicitLayout : 假 类:真 接口:假 IsValueType : 假 IsAbstract : 错误 IsSealed : 真 IsSpecialName : 假 IsImport : 假 IsSerializable : 真 IsAnsiClass : 真 IsUnicodeClass : 假 IsAutoClass : 假 IsArray : 真 IsByRef : 假 指针:假 IsPrimitive : 错误 IsCOMObject : 假 有元素类型:真 IsContextful : 假 IsMarshalByRef : 假 通用类型参数:{} 自定义属性:{[System.SerializableAttribute()]}