我嘗試定義像這樣的自定義方法的對象,但我syntaxe是錯誤的:如何創建具有屬性和方法[PsCustomObject]
$Obj = [pscustomobject]@{
A = @(5,6,7)
B = 9
Len_A = {return $this.A.count;}
Sum_A = {return (SumOf $this.A);}
}
使用,如:
$Obj.Len_A() # return 3
$Obj.A += @(8,9) # @(5,6,7,8,9)
$Obj.Len_A() # return 5
您定位的是哪個版本的PowerShell? –