Get-ADGroup wild card confusion

Good morning experts!
Running the following script:

$GNames = Import-CSV -Path D:\Powershell_temp\danea_info.csv| ForEach-Object { 
    Get-ADGroup -Filter "Name -like '*$($_.name)*'" } | Select-Object Name

is not working the way I thought it was. The only way I can produce output in $GNames is to place * around $($_.name) In doing that I’m
getting additional groups that are not in the input csv file. So the obvious solution to my feeble mind would be to remove the second wildcard, nope no worky removing the second wildcard the $GNames is empty, removing both wildcards $GNames is empty. Obviously not doing something right, please advise and correct my ignorance.

Thank you

Norm

Works perfectly for me. Without the * wildcards, you might as well use -eq instead of -like. What does the csv look like? Are they exact matches for group names?

Good afternoon,
It’s still not working for me the following was in the input file BUT not in $GNames dgMSEPP-ServerSQL. They are exact matches of Group Names. Here is the entry in the .csv file dgMSEPP-ServerSQL There is a since of urgency on this, need to get this script which I thought was working by 4pm PST today.

Thank you for your help
Norm

I don’t see the input file?

Good afternoon,
Looks like I’ve been sabotaged. It appears another admin may have deleted some of the group entries in their spreadsheet sent to me. So the following does indeed work

$GNames = Import-CSV -Path D:\Powershell_temp\danea_info.csv| ForEach-Object { 
    Get-ADGroup -Filter "Name -eq '$($_.name)'" -Properties Name } | Select-Object Name 

Apologize for the additional posts, good to know haven’t lost my mind

Thanks again

Norm

Glad it’s resolved.

Take the file out of the mix.

# So, if you did this generally...

$GroupArray = 'AD','ADS'

$GroupArray | %{(Get-ADGroup -Filter "Name -like '$PSItem*'").Name}

$GroupArray | %{(Get-ADGroup -Filter "Name -like '*$PSItem*'").Name}

# ... that you don't get back what is expected?