10.19.2016

Exchange 2016 Powershell Script to add list of users as owners to a distribution list

Exchange 2016 Powershell Script to add list of users as owners to a distribution list

Start-Transcript

CLS
Write-Output `n`n

$Users = Import-Csv .\ACLGroupMembers.csv

ForEach ($User in $Users){

    $error = $null

    Write-Output "Adding:   '$User.DisplayName'" -ForegroundColor Green
    Write-Output "To Group: '$User.DL'" -ForegroundColor Green
   
    Set-DistributionGroup -Identity $User.DL -ManagedBy @{Add=$User.Alias}

    If($error = $null){Write-Output "Result: Successful"}
    Else {
Write-Output "Result:  '$error'"
}

    Write-Output `n
}#End of For-Each Statement

Write-Output `n`n


Stop-Transcript

The excel spreadsheet (ACLGroupMembers.csv) should have two columns. Column A shows "Alias", while Column B shows "DL". Put the username in column A, and the Alias of the Distribution Group in Column B.

The transcript is used to record the output should any errors appear in the running of the Powershell Script. This also needs to be run in the Exchange Management Shell.



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.