Link to home
Start Free TrialLog in
Avatar of Alex
AlexFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Get Samaccountname from email

Afternoon

My brain is fried, I'm feeling rough and sweating loads.

$users = Import-csv C:\temp\Manager.csv
foreach ($User in $Users){

 Get-aduser -Properties * -Filter {(mail -like $_.'Line Manager Email')}}

Open in new window



Why isn't this working?
Avatar of oBdA
oBdA

Most likely reason: you're using the ForEach statement with a named loop variable, not the ForEach-Object cmdlet, but are using "$_" as loop variable in the filter. Change either the loop type or the variable and try again.
Avatar of Alex

ASKER

So something like this?

Import-csv C:\temp\Manager.csv | foreach-object | Get-aduser -Properties * -Filter {(mail -like $_.'Line Manager Email')}

I tried that and it still didn't like it :(
Avatar of Alex

ASKER

I also tried

$users = Import-csv C:\temp\Manager.csv
foreach ($User in $Users){

 Get-aduser -Properties * -Filter {(mail -like $user.'Line Manager Email')}}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Alex

ASKER

Urgh, powershell is silly.... :(

Thank you, at least it wasn't entirely me being stupid.