So basically I'm trying to return a list of accounts that doesn't match the ones in my whitelist.
And I'm doing so this way.
$UserList = Get-ADUser -Filter * -Server $domain | select -Property Name, samAccountName
$checkUsers = $UserList | Select-String -pattern $whitelist -notMatch
Now $checkUsers
stores the values as (hashtables from what I can understand) returned from Select-String
as such.
@{Name=user1; samAccountName=user1}
@{Name=user2; samAccountName=user2}
@{Name=user3; samAccountName=user3}
I've tried so many things to bored you with the details so I'll just make it short, I'll get straight to the point, I'm losing my sanity at this point...
How can turn this into an object so I can: As example.
ForEach ($user in $myNewObject) { Write-Host $user.Name }
If I create a hashtable myself and store some values in it, I can access the no problem but when its returned from the output of Select-String
, I can' do anything with it...