【发布时间】:2015-05-22 23:03:15
【问题描述】:
我正在尝试从数组中删除项目,但无论我使用什么方法,它似乎都不起作用。我需要一些帮助来了解这里发生的事情。
我通常默认使用System.Array,但这不起作用,我now understand why:
[array]$arrADComputers = Get-ADComputer -Filter 'OperatingSystem -like "Windows 7 Enterprise" ' -Properties Name | select name
$arrADComputers.GetType()
$arrADComputers.count
$arrADComputers.Remove("Machine")
$arrADComputers.count
所以我尝试使用System.Collections.ObjectModel.Collection,但这也不起作用。
$Collection1 = {$arrADComputers}.Invoke()
$Collection1.GetType()
$Collection1.Count
$Collection1.Remove("Machine")
$Collection1.count
System.Collections.ArrayList也是如此
[System.Collections.ArrayList]$Collection2 = $arrADComputers
$Collection2.GetType()
$Collection2.Count
$Collection2.Remove("Machine")
$Collection2.count
但是如果我像这样创建一个数组,它可以正常工作:
[System.Collections.ArrayList]$Trash1 = 1,"this",2,"that",3,"them","4"
$Trash1.GetType()
$Trash1.Count
$Trash1.Remove("that")
$Trash1.Count
$TrashTmp = 1,"this",2,"that",3,"them","4"
$Trash2 = {$TrashTmp}.Invoke()
$Trash2.GetType()
$Trash2.Count
$Trash2.Remove("that")
$Trash2.Count
我没有理解哪些概念会阻止我从数组中删除项目?
【问题讨论】:
标签: .net arrays powershell