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 "EDS 그룹이 없습니다. 그룹 생성 중."              net group "EDS Servers" /ADD /DOMAIN 2>&1 | Out-Null          }                     $exitCode = (get-variable LastExitCode).Value          if ($exitCode)          {              Write-ExchangeSetupLog -Error "EDS Servers 보안 그룹을 만들 수 없습니다."          }          else          {              Write-ExchangeSetupLog -Info "EDS Servers 보안 그룹을 만들었습니다."          }           # 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 "EDS Servers 보안 그룹을 AD에서 찾을 수 없습니다."          }          $edsServers = $searchResult.GetDirectoryEntry()          if ($edsServers -eq $null)          {              Write-ExchangeSetupLog -Error "EDS Servers 보안 그룹에 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 "Exchange Servers 보안 그룹을 AD에서 찾을 수 없습니다."          }          $exchangeServers = $searchResult.GetDirectoryEntry()          if ($exchangeServers -eq $null)          {              Write-ExchangeSetupLog -Error "Exchange Servers 보안 그룹에 AD에 디렉터리 항목이 없습니다."          }          $exchangeServersDN = $exchangeServers.DistinguishedName[0]          if (-not $edsServers.Properties["member"].Contains($exchangeServersDN))          {              $edsServers.Properties["member"].Add($exchangeServersDN)          }          Write-ExchangeSetupLog -Info "Exchange Servers 그룹을 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 "Domain Controllers 보안 그룹을 AD에서 찾을 수 없습니다."          }          $domainControllers = $searchResult.GetDirectoryEntry()          if ($domainControllers -eq $null)          {              Write-ExchangeSetupLog -Error "Domain Controllers 보안 그룹이 AD에 디렉터리 항목을 갖고 있지 않습니다."          }          $domainControllersDN = $domainControllers.DistinguishedName[0]          if (-not $edsServers.Properties["member"].Contains($domainControllersDN))          {              $edsServers.Properties["member"].Add($domainControllersDN)          }          Write-ExchangeSetupLog -Info "Domain Controllers 그룹을 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 "Central Admin SQL Servers 보안 그룹이 AD에 디렉터리 항목을 갖고 있지 않습니다."              }              $centralAdminSQLServersDN = $centralAdminSQLServers.DistinguishedName[0]              if (-not $edsServers.Properties["member"].Contains($centralAdminSQLServersDN))              {                 $edsServers.Properties["member"].Add($centralAdminSQLServersDN)              }              Write-ExchangeSetupLog -Info "Central Admin SQL Servers 그룹을 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 "NAT Servers 보안 그룹이 AD에 디렉터리 항목을 갖고 있지 않습니다."              }              $natServersDN = $natServers.DistinguishedName[0]              if (-not $edsServers.Properties["member"].Contains($natServersDN))              {                 $edsServers.Properties["member"].Add($natServersDN)              }              Write-ExchangeSetupLog -Info "NAT Servers 보안 그룹을 EDS Servers 보안 그룹에 추가했습니다."          }                     $edsServers.CommitChanges()          Write-ExchangeSetupLog -Info "EDS Servers 그룹을 커밋했습니다."