I want to delete objects inside of a Arraylist. Since I'm new to Powershell I found myself in quite a bit of trouble.
More Specifically I want to delete Objects inside of the first Arraylist and if the object is the same as in the second Arraylist it should get removed.
Here is what I tried so far. As a reference I tried to use this page: 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
Is something as this possible, or did I try the wrong solution.
Would love to hear any tips or advice.