Wednesday, July 27, 2016

Skype For Business - Reports for Users with Enterprise Voice Enabled and their Extensions.

Skype For Business 2015 - Reports for Users with Enterprise Voice Enabled and their Extensions.

#Create table and populate users properties
$table = @()

#Get users who have Enterprise Voice Enabled and select Name, LineURI and #EnterpriseVoiceEnabled columns
$users = Get-CsUser -Filter {EnterpriseVoiceEnabled -eq $true} | `
Select DisplayName, LineURI, EnterpriseVoiceEnabled

#Loop through each users
foreach($user in $users){

#Get Name from the user list for each user
$name = $user.DisplayName
#Grab extension which is after = sign and grab the 1st part after =
$ext = $user.LineURI.Split("=")[1]
#Grab value of EnterpriceVoiceEnabled in this case it will be always True
#cause our initial search only includes Enterprise Enabled users.
$entvoice = $user.EnterpriseVoiceEnabled


#Add each columns with property for users.
$objAverage = New-Object System.Object
$objAverage | Add-Member -type NoteProperty -name "User" -value $name
$objAverage | Add-Member -type NoteProperty -name "Extension" -value $ext
$objAverage | Add-Member -type NoteProperty -name "Enterprise Voice" -value $entvoice

#Add them to table
$table += $objAverage

#Format the table. This is useless as we are sending email from below $body
$table | Format-Table -AutoSize
}

#CSS formating
$a = "<style>"
$a = $a + "BODY{background-color:white;}"
$a = $a + "TABLE{border-width: 2px;border-style: solid;`
border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 2px;padding: 2px;`
border-style: solid;border-color: black;background-color:GoldenRod}"
$a = $a + "TD{border-width: 2px;padding: 2px;border-style: `
solid;border-color: black;background-color:palegoldenrod}"
$a = $a + "</style>"

##############Change your SMTP Details Start###
#Your SMTP server
$smtpServer = "intermailserver.usyse.com"

#Your from address
$from = "Do_Not_Reply@usyse.com"

$To = "me@usyse.com", "you@usyse.com"
$CC = "someone@usyse.com"

##############Change your SMTP Details Ends### 
$Subject = "Skype For Business Extensions"

$Body  = "Skype For Business Extension Details<br>

 <br>
"
#Here I am sorting it out with Extension
$Body  += $table  | Sort-Object Extension | ConvertTo-Html -head $a
$Body  += "<br><br>"
#$message.Body  += " <br>"
#$message.Body  += " <br>"
$Body  += " "


#Send email finally

Send-MailMessage -To $to  -Subject $subject -Body $body -SmtpServer $smtpserver -From $from -BodyAsHtml  -Cc $CC