Check to see if the group exists # Must perform detection for Local and Global/Universal Group separately and combine the ...

# Check to see if the group exists          # Must perform detection for Local and Global/Universal Group separately and combine the results          net localgroup "EDS Servers" /domain 2>&1 | Out-Null          $LocalGroup = (get-variable LastExitCode).Value          net group "EDS Servers" /domain 2>&1 | Out-Null          $GlobalGroup = (get-variable LastExitCode).Value          $GroupExists = !($LocalGroup -and $GlobalGroup)           if (!$GroupExists)          {              Write-ExchangeSetupLog -Info "El grupo EDS no existe, se está creando el grupo"              net group "EDS Servers" /ADD /DOMAIN 2>&1 | Out-Null          }                     $exitCode = (get-variable LastExitCode).Value          if ($exitCode)          {              Write-ExchangeSetupLog -Error "No se puede crear el grupo de seguridad EDS Servers"          }          else          {              Write-ExchangeSetupLog -Info "El grupo de seguridad EDS Servers se ha creado correctamente"          }           # Add all Exchange servers and domain controllers to the group with access to the DKM container.          # They have EDS installed.          $ds = new-object -type system.directoryservices.directorysearcher -argumentlist "(&(objectClass=group)(cn=EDS Servers))"          $searchResult = $ds.FindOne()          if ($searchResult -eq $null)          {              Write-ExchangeSetupLog -Error "No se encuentra el grupo de seguridad EDS Servers en AD."          }          $edsServers = $searchResult.GetDirectoryEntry()          if ($edsServers -eq $null)          {              Write-ExchangeSetupLog -Error "El grupo de seguridad EDS Servers no tiene una entrada de directorio en AD."          }          # Make sure EDS Servers is a universal group.          $universalSecurityGroup = 0x80000008          $edsServers.InvokeSet("groupType", $universalSecurityGroup)          $edsServers.CommitChanges()          $ds = new-object -type system.directoryservices.directorysearcher -argumentlist "(&(objectClass=group)(cn=Exchange Servers))"          $searchResult = $ds.FindOne()          if ($searchResult -eq $null)          {              Write-ExchangeSetupLog -Error "No se encuentra el grupo de seguridad Exchange Servers en AD."          }          $exchangeServers = $searchResult.GetDirectoryEntry()          if ($exchangeServers -eq $null)          {              Write-ExchangeSetupLog -Error "El grupo de seguridad Exchange Servers no tiene una entrada de directorio en AD."          }          $exchangeServersDN = $exchangeServers.DistinguishedName[0]          if (-not $edsServers.Properties["member"].Contains($exchangeServersDN))          {              $edsServers.Properties["member"].Add($exchangeServersDN)          }          Write-ExchangeSetupLog -Info "El grupo Exchange Servers se ha agregado correctamente al grupo de seguridad EDS Servers."          $ds = new-object -type system.directoryservices.directorysearcher -argumentlist "(&(objectClass=group)(cn=Domain Controllers))"          $searchResult = $ds.FindOne()          if ($searchResult -eq $null)          {              Write-ExchangeSetupLog -Error "No se encuentra el grupo de seguridad Domain Controllers en AD."          }          $domainControllers = $searchResult.GetDirectoryEntry()          if ($domainControllers -eq $null)          {              Write-ExchangeSetupLog -Error "El grupo de seguridad Domain Controllers no tiene una entrada de directorio en AD."          }          $domainControllersDN = $domainControllers.DistinguishedName[0]          if (-not $edsServers.Properties["member"].Contains($domainControllersDN))          {              $edsServers.Properties["member"].Add($domainControllersDN)          }          Write-ExchangeSetupLog -Info "El grupo Domain Controllers se agregó correctamente al grupo de seguridad EDS Servers."          $ds = new-object -type system.directoryservices.directorysearcher -argumentlist "(&(objectClass=group)(cn=Central Admin SQL Servers))"          $searchResult = $ds.FindOne()          if ($searchResult -ne $null)          {                            $centralAdminSQLServers = $searchResult.GetDirectoryEntry()              if ($centralAdminSQLServers -eq $null)              {                 Write-ExchangeSetupLog -Error "El grupo de seguridad Central Admin SQL Servers no tiene una entrada de directorio en AD."              }              $centralAdminSQLServersDN = $centralAdminSQLServers.DistinguishedName[0]              if (-not $edsServers.Properties["member"].Contains($centralAdminSQLServersDN))              {                 $edsServers.Properties["member"].Add($centralAdminSQLServersDN)              }              Write-ExchangeSetupLog -Info "El grupo Central Admin SQL Servers se agregó correctamente al grupo de seguridad EDS Servers."          }                    $ds = new-object -type system.directoryservices.directorysearcher -argumentlist "(&(objectClass=group)(cn=NAT Servers))"          $searchResult = $ds.FindOne()          if ($searchResult -ne $null)          {                            $natServers = $searchResult.GetDirectoryEntry()              if ($natServers -eq $null)              {                 Write-ExchangeSetupLog -Error "El grupo de seguridad NAT Servers no tiene una entrada de directorio en AD."              }              $natServersDN = $natServers.DistinguishedName[0]              if (-not $edsServers.Properties["member"].Contains($natServersDN))              {                 $edsServers.Properties["member"].Add($natServersDN)              }              Write-ExchangeSetupLog -Info "El grupo de seguridad NAT Servers se agregó correctamente al grupo de seguridad EDS Servers."          }                     $edsServers.CommitChanges()          Write-ExchangeSetupLog -Info "El grupo EDS Servers se confirmó correctamente."