Evaluating AD Attribute list output

I am writing a script that will eventually edit the ‘showinAddressBook’ attributes within Active Directory but first I just want to see if a specific String resides within the list but this does not give me accurate output. I ‘believe’ I am not understanding the ‘type’ of output I am dealing with. Maybe it is not string data. The output tells me that known of the contacts contain the string but i know that is not true.

$Entry = "CN=AmericanSokol Global Address List,CN=All Global Address Lists,CN=Address Lists Container,CN=TechPro-Hosted-Org,CN=Microsoft Exchang
e,CN=Services,CN=Configuration,DC=techpro,DC=local"

$Contacts = Get-ADObject -Filter  {(objectclass -eq 'contact')}  -SearchBase "OU=AmericanSokol, OU=Hosted,DC=techpro, dc=local" -Properties showinaddressbook 
foreach ($Contact in $Contacts)
{
   
   if ($Contact.showinaddressbook -like $Entry)
   {
      Write-Host $Contact.Name contain List
   }
   else
   {
      Write-Host $Contact.Name does not contain List   
   }    
   
}

This is the output

Jara Dusatko does not contain List
Jerry Milan does not contain List
Jerry Sjansky does not contain List
Judi Soulides does not contain List
Larry Svestka does not contain List
Lillian Roter does not contain List
Marla Breidenbach does not contain List
Mary Ellen Newsom does not contain List
Mike Dropka does not contain List
Mike Rokos does not contain List
Renata Greene does not contain List
Richie Vachata does not contain List
Ronald Merecka does not contain List
Shane Bivens does not contain List
Sonia Riecan does not contain List
Theresa Vernon does not contain List
Tibor Bartalos does not contain List
Tom & Judy Aubrecht does not contain List
Tony Rospotynski does not contain List
Vera Wilt does not contain List
aso emails-JeanHruby does not contain List
Jean Hruby-Gmail does not contain List
Allen Cushing does not contain List
Allison Gerber does not contain List
Bev Domzalski does not contain List
Bob Podhrasky does not contain List
Donna Tirva does not contain List
Ethna Flaherty- national ED does not contain List
Jane Wise does not contain List
Jolene Dalton does not contain List
Kathy Barcal does not contain List
Lynda Filipello does not contain List
Maryann Fiordelis does not contain List
Meribeth Tooke does not contain List
Roger Martanovic does not contain List
Bar Vondra does not contain List
Chris Yatchyshyn does not contain List
Chris Kalat does not contain List
Cynthia Duff does not contain List
Dan Bajek does not contain List
Deb Allison does not contain List
Donna Sbriglia does not contain List
Jason Brozovich does not contain List
John Mooney does not contain List
Joseph Ehrenberger does not contain List

Try changing the comparison operator in your if statement from -like to -match or -contains. If you use the -match operator, you will need to change the quotation marks in $Entry from double to single quotes.

Hi,
showInAddressBook is a multi-valued attribute and therefore can contain more than one Address List. So you should use -contains like Matt suggests.

Also, on a side note you don’t manipulate or edit this property. Exchange manages it based on the filters of the AL’s/GAL’s you have defined in your environment.

Dave.