Hello Techies out there.
So after I built the Activation Check script https://gallery.technet.microsoft.com/Exchange-2013-Activation-7e95afff/view/Discussions#content
I am working on a script where I need a list with Custom Attribute Value and the count for it. I used the same code reference and built the below. I am able to get the output but it displays the same name again and again. Although the count is ok.
Can anyone help me that how I can display only the Name Once and the Count against it.
Right now the table is like somethig as below
CA Name Count
xxx1,xxx1,xxx1,xxx1,xxx2,xxx2,xxx3 11
xxx1,xxx1,xxx2,xxx2
I want something like
CA Name Count
XXX1 6
XXX2 4
Below is the Code that I wrote
########################### Add Exchange Shell############################## If ((Get-PSSnapin | where {$_.Name -match "Microsoft.Exchange.Management.PowerShell"}) -eq $null) { Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn } ######################### generate the HTML################################# function _Drawme { $Output ="<html><body><font size=""1"" face=""Arial,sans-serif""><h3 align=""center""><font color=""FF0000"">Exhange Audit Report</h3><h5 align=""center""><font color=""000000"">Generated $((Get-Date).ToString())</h5></font>" if($cacount.count -ne 0) { $Output+="<table border=""0"" cellpadding=""3"" width=""50%"" style=""font-size:8pt;font-family:Arial,sans-serif""><tr align=""center"" bgcolor=""#81B5F9"">" $Output+="<th>#</th><th>CA Name</th><th>Count Covered</th>" $Output+="</tr>" $AlternateRow=0; foreach ($mbx in $cacount) { $C++ $Output+="<tr" if ($AlternateRow) { $Output+=" style=""background-color:#CFE2FF""" $AlternateRow=0 } else { $AlternateRow=1 } $Output+=">" $Output+="<td align=""center""><strong>$C</strong></td>" $Output+="<td align=""center""><font color=""#FF0015""><Strong>$($caname)</Strong></font></td><td align=""center""><font color=""#FF0015""><Strong>$($cacount)</Strong></font></td>" } $Output+="</table><br />" } Write-Output $Output } #########################Get The Databases################################## $serverObj = New-Object PSObject $mailboxes = Get-Mailbox ForEach ($mailbox in $mailboxes) { $mbx = $mailbox.Name $caname = $mailboxes.CustomAttribute2 $cacount = $caname.Count # Compare the server where the DB is currently active to the server where it should be If ($cacount -ne 0) { $serverObj | Add-Member NoteProperty -Name "SourceOne Group" -Value "$caname" -Force $serverObj | Add-Member NoteProperty -Name "Number of Mailboxes Covered" -Value "$cacount" -Force } } if ($cacount.count -ne 0) { Write-Host "CA Found....Sending Email" -ForegroundColor Red $Output= _Drawme #Send the Email Send-MailMessage -From "noreplyaudit@xx.com" -To "Recipient 1 <user1.xx.com>" -Subject "Exchange Audit Report" -BodyAsHtml $Output -Priority High -SMTPserver "smtp.xx.com" } Else{ Write-Host "Nothing Found!!!!!!!!!" -ForegroundColor Green }Also I ould like to add another column in case no values found the Count for that is Shown up
All help would be appreciated ... Thanks Guys...