O365 Set-Distribution Group Email Address Policy

This topic contains 2 replies, has 2 voices, and was last updated by  Juli 4 months, 1 week ago.

  • Author
    Posts
  • #75265

    Juli
    Participant

    I am in the beginning stages of testing our bulk distribution group, contact and mailbox creations scripts for o365. In testing the script I am using for creating distribution groups, I received an error that the -emailaddresspolicyenabled $true couldn't be found as a parameter. Everything I have looked at shows it being used with the set-distribution group command. Any assistance would be greatly appreciated.

    $credential = Get-Credential
    
    Import-Module MsOnline
    Connect-MsolService -Credential $credential
    
    $exchange365 = New-PSSession -ConfigurationName Microsoft.exchange -ConnectionUri https://outlook.office365.com/powershell-liveid -Credential $credential -Authentication Basic -AllowRedirection
    Import-PSSession $exchange365 -DisableNameChecking
    
    $distrogroup = Import-csv c:\temp\o365group.csv
    $filename = "c:\temp\members.csv"
    
    
    foreach ($i in $distrogroup) 
        {
               
          new-distributiongroup -Name $i.Name -Alias $i.Alias -primarysmtpaddress $i.Smtp -OrganizationalUnit $i.OrganizationalUnit -ManagedBy $i.manager 
                     
        }
    
        sleep 120
    
    foreach($i in $distrogroup)
    
        {
            $groupname = $i.name
                       
            set-distributiongroup $groupname -RequireSenderAuthenticationEnabled $FALSE -EmailAddressPolicyEnabled $true 
    
        }
    
     sleep 240
        
    if(Test-Path $filename)
    {
    
    $members = Import-csv c:\exchangetools\members.csv
    
    foreach ($i in $members) 
    
    {add-distributiongroupmember $i.groupname -Member $i.Name }
    
    
  • #75269

    Hi

    https://technet.microsoft.com/en-us/library/bb124955(v=exchg.160).aspx

    EmailAddressPolicyEnabled
    This parameter is available only in on-premises Exchange 2016.
    $true Email address policies are applied to this recipient. This is the default value.

    Seems like you need to remove it if you're not using onpremise Exchange. Also why you have these sleep commands? You could add all these into one ForEach loop.

    $credential = Get-Credential
    
    Import-Module MsOnline
    Connect-MsolService -Credential $credential
    
    $exchange365 = New-PSSession -ConfigurationName Microsoft.exchange -ConnectionUri https://outlook.office365.com/powershell-liveid -Credential $credential -Authentication Basic -AllowRedirection
    Import-PSSession $exchange365 -DisableNameChecking
    
    $distrogroup = Import-csv c:\temp\o365group.csv
    $filename = "c:\temp\members.csv"
    
    foreach ($i in $distrogroup) {
               
          new-distributiongroup -Name $i.Name -Alias $i.Alias -primarysmtpaddress $i.Smtp -OrganizationalUnit $i.OrganizationalUnit -ManagedBy $i.manager 
    
        set-distributiongroup $i.Name -RequireSenderAuthenticationEnabled $FALSE
    
    }
        
    $members = Import-csv c:\exchangetools\members.csv
    
    foreach ($i in $members) {
        add-distributiongroupmember $i.groupname -Member $i.Name
    }
    
    

    Regards

    Jarkko

    • #75284

      Juli
      Participant

      The sleep commands are there to provide enough time for the groups to be available to set. Without them I run into an issue where it can't get the group to set the additional attributes. It takes a bit longer on the back end.

You must be logged in to reply to this topic.