Filter Mg-User with value from csv file

Filter Mg-User like this:
foreach ($own in import-csv -path c:\Users\580616\DistinctOwners.csv) {(get-mguser -consistencylevel eventual -filter (displayname eq “$own.owner”))}

… or…
foreach ($own in import-csv -path c:\Users\580616\DistinctOwners.csv) {(get-mguser -consistencylevel eventual -filter “(displayname eq $own.owner)”)}

They don’t work!

What does it do, is there an error? We can not see your screen or read minds please give more detail.

Sorry, I get different errors: The first way yields:
displayname: The term ‘displayname’ is not recognized as a name of a cmdlet, function, script file, or executable program.

The other way: Invalid filter clause

This script works fine!
clsforeach ($own in import-csv -path c:\Users\580616\DistinctOwners.csv) {(echo “$own.owner”)}

When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to help you potentially wasting their time.

Thanks

That post is from 2009. :person_shrugging:

Try it with a subexpression:

Get-MgUser -Filter "displayname eq '$($own.owner)'"
1 Like

It’s a closed thread. SO is already rerouting the link to the linked answer. :man_shrugging:t3:

I apologize. In the future, I will keep track of where I post. I guess that should be obvious. I am sorry for being sloppy.

YES!!!

foreach ($own in import-csv -path c:\Users\580616\DistinctOwners.csv) {(get-mguser -consistencylevel eventual -filter “(displayname eq ‘$($own.owner)’)”)}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.