【发布时间】:2018-11-09 08:48:32
【问题描述】:
我在 Powershell 中创建了一个如下所示的对象:
Class groupObject{
[string] $Name
[string] $Domain
groupObject([string] $inputName, [string] $inputDomain){
$this.Name = $inputName
$this.Domain = $inputDomain
}
setName([string] $inputName){
$this.Name = $inputName
}
setDomain([string] $inputDomain){
$this.Domain = $inputDomain
}
[string] getName(){
return $this.Name
}
[string] getDomain(){
return $this.Domain
}
# Compare two groupObjects.
[boolean] isEqual([groupObject] $ADgroup){
return ($ADgroup.getName() -eq $this.getName() -and $ADgroup.getDomai() -eq $this.getDomain())
}
}
我有两个 ArrayList,其中包含来自不同来源的 groupObjects。
现在我想比较这两个列表并找到仅在其中一个列表中的所有组。我正在尝试使用类似$onlyList2= $List2 | ?{$List1 -notcontains $_} 的东西。但我不确定如何使用我的groupObjects 来做到这一点。有什么建议吗?
【问题讨论】:
-
你试过
Compare-Objectcmdlet吗?
标签: powershell class compare