【发布时间】:2022-01-10 15:54:45
【问题描述】:
我想删除 Arraylist 中的对象。由于我是 Powershell 新手,我发现自己遇到了很多麻烦。
更具体地说,我想删除第一个 Arraylist 中的对象,如果该对象与第二个 Arraylist 中的对象相同,则应将其删除。
这是我到目前为止所尝试的。作为参考,我尝试使用此页面:https://www.sapien.com/blog/2014/11/18/removing-objects-from-arrays-in-powershell/
[System.Collections.ArrayList]$everyExistingFolder = (Get-ChildItem -Path "$PSScriptRoot\test" | foreach { $_.Name })
[System.Collections.ArrayList]$everyFolderWichShouldExist = (Get-Content "$PSScriptRoot\directoriesADExport.txt")
$output = ForEach ($element in $everyExistingFolder)
{
if($element -eq $everyFolderWichShouldExist){
$everyExistingFolder.Remove($element)
}
}
Out-File $output
这是可能的,还是我尝试了错误的解决方案。
很想听听任何提示或建议。
【问题讨论】:
标签: powershell arraylist