Change DistributionGroup Settings Remote Domain

Welcome Forums General PowerShell Q&A Change DistributionGroup Settings Remote Domain

Viewing 3 reply threads
  • Author
    • #214821
      Topics: 1
      Replies: 1
      Points: 34
      Rank: Member

      I am running a script that connects to a remote exchange computer in another domain and sets an attribute on a Distribution Group.  When I run the lines of code manually in an Exchange PowerShell window on my machine, it runs as expected.  Then when I run it in a script that calls the same remote PowerShell, it errors for what seems to be authentication.

      Script that I am running:

      # Create Variables
      Set-Variable -Name Sam
      Set-Variable -Name DisplayName
      Set-Variable -Name TADServer 
      Set-Variable -Name SADServer 
      Set-Variable -Name SourceCred
      Set-Variable -Name TargetCred
      Set-Variable -Name EmailAddresses
      Set-Variable -Name Attribute7 
      Set-Variable -Name Session
      # Clear Variables
      Clear-Variable Sam
      Clear-Variable DisplayName
      Clear-Variable TADServer 
      Clear-Variable SADServer 
      Clear-Variable SourceCred
      Clear-Variable TargetCred
      Clear-Variable EmailAddresses
      Clear-Variable Attribute7 
      Clear-Variable Session
      #Set Inital Variable Value
      $TADServer = "Target DC FQDN"
      $SADServer = "Source DC FQDN"
      #Input Creditials for Source Active Directory
      Write-Host = "Requesting Credentials for Source Active Directory."
      $SourceCred = Get-Credential
      #Input Creditials for Target Active Directory
      #Write-Host = "Requesting Credentials for Target Active Directory."
      #$TargetCred = Get-Credential
      Import-Csv 'Path to CSV File' | ForEach-Object {
          # Connect Remote Exchange PowerShell Session
        Write-Host "Connecting to Remote Exchange Server"
        Enter-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://FQDN/powershell -Authentication Kerberos -Credential $SourceCred
          Write-Host "Connected to the Remote Exchange Server"
        Start-Sleep 10
          # Set Variables for Remote PowerShell Session
        $SADServer = "Source DC FQDN"
        $Attribute7 = "NoSyncO365"
          $DisplayName = $_."DisplayName"
          Write-Host "Importing Distribution Group: " $DisplayName
        $Sam = $_."SamAccountName"
        $EmailAddresses = $_."EmailAddresses"
          # Set Source Distribution Group extensionAttribute7 to Not Sync with O365
        Set-DistributionGroup $Sam -DomainController $SADServer -customAttribute7 $null
          Set-DistributionGroup $Sam -DomainController $SADServer -customAttribute7 $Attribute7
          Write-Host "Disonnected from the Remote Exchange Server"
        # Run AD Sync to remove Legacy User
        Start-Sleep -Seconds 120
          # Import Data to Target AD Distribution Group
        Enable-DistributionGroup -Identity $DisplayName
          Set-DistributionGroup $Sam -DomainController $TADServer -EmailAddresses $EmailAddresses
          Set-DistributionGroup $Sam -DomainController $TADServer -customAttribute7 $null
          Start-Sleep -Seconds 120
    • #214995
      Topics: 4
      Replies: 82
      Points: 251
      Helping Hand
      Rank: Contributor

      Can you post the actual error?

    • #215136
      Topics: 1
      Replies: 1
      Points: 34
      Rank: Member

      The error that I get is below:

      An Active Directory error 0x52 occurred when trying to check the suitability of server ‘Source AD FQDN’. Error: ‘Active directory response: A

      local error occurred.’
          + CategoryInfo         : NotSpecified: (:) [Set-DistributionGroup], SuitabilityDirectoryException
          + FullyQualifiedErrorId : [Server=CAS1601,RequestId=ded099e1-575e-45c8-946d-70d3f363c463,TimeStamp=4/2/2020 5:02:42 PM] [FailureCategory=Cmdlet-Suitabi
        lityDirectoryException] C37AB760,Microsoft.Exchange.Management.RecipientTasks.SetDistributionGroup
          + PSComputerName       : ‘Target Exchange FQDN’

    • #216183
      Topics: 3
      Replies: 324
      Points: 1,056
      Helping Hand
      Rank: Community Hero

      <p style=”background: white; vertical-align: baseline; margin: 0in 0in .25in 0in;”>When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to you help making their work twice or more.</p>


      Please check these links.


      Can you try specifying the server to authenticate against? The issue seems to be with the user account or domain/dc.

      Please let me know if it helps.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.