Compare two dynamic variables


hello,

i'm struggeling comparing 2 variables against each other seen below. have ad-group names in csv file, , have  variable($getgroup) results get-adgrup-query.

i'd filter out groups of csv-file variable, "$getgroup" in example should end empty. 

in example below, return 2 groups, doesn't filtered out. how can that?

contents of exclude.csv: name,comment "ad,group1","some comment" "ad*group2","some comment"   $excluded = import-csv 'c:\temp\exclude.csv' $getgroup = get-adgroup -filter * | where-object {$_.name -like '*,*' -or $_.name -like '*#*' -or $_.name -like '*+*' -or $_.name -like '*"*' -or $_.name -like '*\*' -or $_.name -like '*<*' -or $_.name -like '*>*' -or $_.name -like '*;*'}  #at point $getgroup returns 2 groups; ad,group1 , ad*group2 $getgroup = $getgroup | where-object {$_.name -notlike $excluded.name}  $getgroup


hi,

if have actual group names in input csv, try this:

$excludedgroups = import-csv .\excludegroups.csv | select -expandproperty name  get-adgroup -filter * -searchbase 'ou=testing,dc=domain,dc=com' |     { $excludedgroups -notcontains $_.name }


don't retire technet! - (don't give yet - 13,085+ strong , growing)



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Group Policy Event ID 1058 Error Code 1326 (The user name or password is incorrect)

Suspicious event log Event ID: 4905

DCOM received error "2147746132" from...