Distribution Lists type


why not returning results?

$name = gc ".\list.txt"  foreach ($user in $name){  $searcher = new-object directoryservices.directorysearcher([adsi]””)   $searcher.filter = “(&(objectclass=group)(samaccountname= $user))”  $founduser = $searcher.findone()   $founduser.properties.grouptype   $value = $founduser.properties.grouptype   if ($value -eq '2')    {    write-output “global distribution group”   }  if ($value -eq '4')    {    write-output “domain local distribution group”   }   if ($value -eq '8')    {    write-output “universal distribution group”   }  if ($value -eq '-2147483646')    {    write-output “global security group”   }  if ($value -eq '-2147483644')    {    write-output “domain local security group”   }  if ($value -eq '-2147483640')    {    write-output “universal security group”   }  }

this should work better:

$users = gc list.txt
foreach($user in $users){ $searcher =[adsisearcher]"samaccountname=$user" if($founduser=$searcher.findone()){ switch ($founduser.properties['grouptype'][0]){ 2 {'global distribution group'} 4 {'domain local distribution group'} 8 {'universal distribution group'} -2147483646 {'global security group'} -2147483644 {'domain local security group'} -2147483640 {'universal security group'} default {'unknown'} } } }


\_(ツ)_/



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered

How do a find data in one file, search for it in another file and if not found, write a custom message to another file