Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

AD user query loop

$
0
0

Hey guys,

I'm trying to loop through a list of users and find the associated accounts in AD. Some of the names are not complete though, so I have to append a wildcard to each of the names.

 

I found out, that the following code works and gives me the correct results:

$users= @("Name1","Name2","Name3")
$users | % {$a="$_*"; Get-ADUser-Filter {Name -like$a}}

If I now try to add the wildcard to the string directly when calling Get-Aduser, it won't work:

$users | % {Get-ADUser-Filter {Name -like"$_*"}}

 

I also tried some variations for adding the wildcard to the string, like"$_*", "$_+*" or "$($_)*", unfortunately with the same result.

 

So my problem actually is already solved, but I'm curious if and how this could be done .

 

Thanks

Mike


Viewing all articles
Browse latest Browse all 8583

Trending Articles