My requirement:
Need to update a DL from a csv
1)remove all the members in the DL
2)Add the members from a csv to the DL
3)Need to generate a report
Which members got updated to the DL and which are removed from the DL based on the CSV and the original DL
Hope my question is not confusing, below is the code i have been trying achieve this but stuck with comparing part
------------------------------
$Import=Import-csv "C:\Users\Test\Desktop\TestDL.txt"
$Diff1 = get-distributiongroupmember -identity "TestDL"
get-distributiongroupmember -identity "TestDL" | remove-distributiongroupmember "TestDL" -Confirm:$false
$Import | ForEach {Add-DistributionGroupMember -Identity "TESTDL" -Member $_.Primarysmtpaddress}
$Diff2 = get-distributiongroupmember -identity "TestDL"
$DLLISTCOUNT = (Get-DistributionGroupMember -identity "TestDL").count
$a = "<style>"
$a = $a + "body{background-color:#dddddd;font-family:CALIBRI;font-size:11pt;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color:black;font-family:CALIBRI;font-size:11pt;}"
$a = $a + "Table{background-color:#dddddd;border-collapse: collapse;}"
$a = $a + "TH{border-width:1px;padding:0px;border-style:solid;border-color:black;}"
$a = $a + "TD{border-width:1px;padding-left:5px;border-style:solid;border-color:black;}"
$a = $a + "</style>"
$Compare = compare-object -referenceobject $Diff1 -differenceobject $Diff2 -Property Name -Passthru
$DLLIST = $Compare | Select-Object Displayname,PrimarySmtpAddress | ConvertTo-Html Displayname, PrimarySmtpAddress -head $a
$mailBody =
@"
</br></br>
<h2>DL Members Updated: </h2></br></br>
$DLLIST</br></br>
"@
Send-MailMessage -Body $mailBody -BodyAsHtml -From " " -To " " -Subject "Updated Blackberry DL" -Encoding $([System.Text.Encoding]::UTF8) -SmtpServer "127.0.0.1" -priority High
-------------------------------------