【发布时间】:2010-11-25 19:58:37
【问题描述】:
我正在尝试对数组中的所有项目使用 PowerShell Add-Member cmd,然后访问我稍后添加的成员,但它没有显示出来。
您可以在以下代码的输出中看到 NoteProperty 似乎存在于 foreach 语句的范围内,但它不存在于该范围之外的同一对象上。
有什么方法可以让这个脚本在两次调用 Get-Member 时都显示 isPrime?
$p = @(1)
$p[0] | %{ add-member -inputobject $_ -membertype noteproperty -name isPrime -value $true; $_ | gm }
$p[0] | gm
输出
TypeName: System.Int32
Name MemberType
---- ----------
CompareTo Method
Equals Method
GetHashCode Method
GetType Method
GetTypeCode Method
ToString Method
isPrime NoteProperty
CompareTo Method
Equals Method
GetHashCode Method
GetType Method
GetTypeCode Method
ToString Method
【问题讨论】:
标签: .net powershell