Bulk Distribution Group Creation RRS feed

  • Question

  • Hello Experts, I need small help, As i need to create bulk DL's along with below parameters but the issue is while running the below code Only one DL is getting created not the rest. Can you pls help me guiding what needs to be changed. Thanks


    CSV Input File

    #TESTDL4,#TESTDL4,#TESTDL4,TESTDL4@dev.domain.local,Alex Fok
    #TESTDL5,#TESTDL5,#TESTDL5,TESTDL5@dev.domain.local,Alex Abra
    #TESTDL6,#TESTDL6,#TESTDL6,TESTDL6@dev.domain.local,Alex Abra



    $CSV = Import-CSV "C:\Scripts\New Folder\DL3.csv"
    $CSV | foreach-Object {
    $Name = $_.Alias
    $Alias = $_.Alias
    $Displayname = $_.DisplayName
    $Email = $_.email
    $Managedby = $_.Managedby
          $Exists = ""
    $Exists = Get-DistributionGroup $Name -ErrorAction SilentlyContinue
    If ($Exists) {
    Write-Host "Distribution Group $Alias Already Exists" -ForegroundColor Yellow
    ELSE {
    New-DistributionGroup -Name $Alias -Alias $Alias -Displayname $Displayname -Managedby $Managedby -PrimarySMTPAddress $Email -OrganizationalUnit "dev.domain.local/FC/Groups" -MemberDepartRestriction Closed -ErrorAction SilentlyContinue
    Write-Host "Distribution Group $Alias has been created" -ForegroundColor Green
    $Error | Out-File "c:\Scripts\New Folder\ErrorLog.txt" -Append

    • Moved by Bill_Stewart Wednesday, November 29, 2017 6:28 PM This is not "fix/debug/rewrite my script for me" forum
    Tuesday, September 26, 2017 4:14 PM

All replies

  • In AD a name should not begin with "#".

    Don't suppress errors.  The errors tell you the cause of the issue.


    • Edited by jrv Tuesday, September 26, 2017 8:01 PM
    Tuesday, September 26, 2017 7:59 PM
  • Thanks , but how come the first one is getting created. And As per the company policy all the DL should start with  "#" Any help what can be done to accomplish this ?


    Wednesday, September 27, 2017 3:16 AM
  • You will never know as long as you are suppressing all errors.


    Wednesday, September 27, 2017 3:34 AM
  • Hello All, Can anyone help with this , need to create the Multiple DL as per mentioned format so any possibilities ?

    Wednesday, October 11, 2017 6:06 AM
  • If you are suppressing all errors then you cannot know why it is failing. Please post the errors.

    If you do not understand PowerShell and you found this script somewhere then we cannot help you.  This forum is for scripters and not people who are just trying to use a script they have found.

    Pleas post the errors you have collected.  Without the errors there is no way to help you.


    Wednesday, October 11, 2017 6:27 AM