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

DCOM received error "2147746132" from...

DFSR RPC replication errors 5014 1726 with large files over VPN

ADFS 3.0 Event ID 4625 | An Error occurred During Logon | Status: 0xC000035B