I'm searching AD with a list of partial computernames. The following works like a charm:
Get-ADComputer -Filter 'Name -like "*comp1*"' | Format-Table Name,DistinguishedName
Output looks like:
Name DistinguishedName
---- -----------------
BLA-Comp1-ABC CN=BLA-Comp1-ABC,OU=WSUS Global Policy,OU=BLABLA,OU=BLABLA
I have a text file of partial computernames I want to call and place in the string portion of the previous code to display the actual computername of all the partials in my list. The following is what I have but its not working. It has something to do with
the string and having a variable inside and I can't figure out how to fix it....
Noworking Code
$computers = get-content C:\Scripts\PartialCompNames.csv
ForEach ($entry in $computers){
Get-ADComputer -Filter 'Name -like "*$entry*"' | Format-Table Name,DistinguishedName
}
It seems to be searching for the literal "*$entry*" instead of the data from the CSV as expected.