1
votes

I have a CSV file with GUIDs and I am trying to create a list that excludes those users.

$excludeADusers_file = Import-Csv "c:\temp\ExcludeUsers.csv"
$excludeADusers = $excludeADusers_file |
                  Select-Object objectGuid |
                  Sort-Object
Get-ADUser -Filter * |
  Where-Object {$excludeADusers -notcontains $_.ObjectGuid} |
  Select Name, objectGuid, Enabled

How do I exclude the list in the CSV file?

1
What is going wrong and what is the structure of your csv? - ConanW
I don't get an error message. I have tried changing -notcontains to -contains and either way it just doesn't display anything. I have tried a couple of different things with the csv file from multiple columns with and without headers and one column with and without headers. Right now the first column is Name and the second column is objectGuid - donL
Change Select-Object objectGuid TO Select-Object -Expand ObjectGuid - EBGreen
@EBGreen That was it! - donL

1 Answers

3
votes

You need to expand the objectGuid property when importing the CSV:

$excludeADusers = $excludeADusers_file |
                  Select-Object -Expand objectGuid |
                  Sort-Object

otherwise you'll end up with a list of custom objects with a GUID property instead of a list of GUIDs.


As a side note, you may want to remove the Sort-Object. Sorting the list doesn't improve lookup speed, so it's just a waste of time and system resources.