compare two strings from different arrays, if one string contains another

I want to compare if one string (f.e. Edi) contains in another string (f.e. Edil). I wrote a script with out-string, because later I need to compare two obejcts (all users from AD with accounts from NTFSsecurity (permission for folders)).

$AlleBenutzer = ("Adam","Edi", "Georg","Kate")
$Benutzer = ("Adaml", "Edil", "Eval")
foreach ($u in $AlleBenutzer) {$L = $u | Out-String ; write-host $L}
foreach ($v in $Benutzer) {$M = $v | Out-String; write-host $M}

foreach ($user in $L) {if ($M -match $user ) {Write-Host $M}}

I become output from line 3 and 4, but no output from line 6. I don’t see my mistake.

Leave a Reply

Your email address will not be published. Required fields are marked *