Q:

Powershell -NotLIke comparison

as a newbie in Powershell I made the following script:
Get-ADUser -SearchBase "OU=BEL,OU=EU,DC=domain,DC=net" -Filter * -Properties * |
    where {$_.cn -NotLike ***$_.l***} |
    Select whenCreated, Name,displayName, sn,  givenName, sAMAccountName, title,
        description, employeeType, info, department, company, homeDirectory,
        scriptPath, physicalDeliveryOfficeName, 
        @{Label='Manager';Expression={
            (Get-ADUser $_.Manager -Properties displayName).displayName}} |
    Export-Csv "Output.csv" -NoTypeInformation -Delimiter ";" -Encoding utf8

start "Output.csv"

As a result I would like to see all users that don't have the City (l) mentioned in their CN (name) field. An example result would be:
CN : John Do (Denver) USA
l: Oklahoma
For one reason or another the sript works perfectly but it doesn't do the compare with the City mentioned in 'l'. It just gives me all the users in the AD, and when passing wildcards Powershell doesn't seem to use them.. Any advise would be really great. Thank you already. 

A:

I don't know why you have three asterisks surrounding $_.l. It should look like one of the following:
where {$_.cn -NotLike "*$($_.l)*"}
where {$_.cn -NotLike "*" + $_.l + "*"}
where {$_.cn -NotLike ("*{0}*" -f $_.l)}

Or you could just use -notmatch:
where {$_.cn -NotMatch $_.l}

