Posts

Showing posts with the label contains

Powershell comparing two List with foreach

Image
Clash Royale CLAN TAG #URR8PPP Powershell comparing two List with foreach I'm trying to compare two lists that I obtained with the Get-ChildItem cmdlet. Get-ChildItem I read about the Compare-Object cmdlet, but in this context I would prefer doing with a foreach because is useful to have access to the $file variable. Compare-Object $file $StartingFolderPath = "C:---StartingFolder" $EndingFolderPath = "C:---EndingFolder" $AllStartingFiles = Get-ChildItem $StartingFolderPath $AllEndingFiles = Get-ChildItem $EndingFolderPath Write-Host "First folder content:"$AllStartingFiles Write-Host "Second folder content:" $AllEndingFiles foreach($file in $AllEndingFiles){ write-Host "Element :" $file.Name $result = $AllStartingFiles.Contains($file.Name) write-host $result if($AllStartingFiles.Contains($file.Name)){ Write-Host "You are here" Write-Host $file.Name } } But it seems that I cannot pass the...