13 May 2014

Powershell: Lync User Report

When I first started in my current position, we were positioning to roll out Lync to all of our users company wide. My boss wanted a way to track how many users we actually had enabled. Rather than giving him a simple number of users by running (Get-CsUser).Count, I wanted to be able to provide him more information. In addition I could easily see how well my pools were balanced. This is actually part of a larger report that I have set up as a daily scheduled task. I decided to break it into two pieces for the blog and will post the combined script after that.

Basically this script collects user counts based on registrar pool and Conferencing policy, puts it into a couple nice tables, and emails the report to me. This script provided here looks at two registrar pools and three Conferencing policies. You should be able to modify this as needed for your environment.

I have run this on my Lync 2010 and 2013 Front End servers.

Download the script here. Some of the HTML code included in the script doesn't show up correctly in the preview below.

#******************************************
#
#   DESCRIPTION: Email Report of Lync users based on Registrar Pool and Conferencing Policy
#   VERSION: 1.0
#   UPDATED: 
#   AUTHOR: Brad Roberts
#   CONTACT: brad@thatucguy.com
#   BLOG: http://www.thatUCguy.com
#   BLOG ENTRY: http://www.thatucguy.com/2014/04/powershell-lync-user-report.html
#
#   DISCLAIMER: You running this script means you won't blame me if this breaks your stuff. This script is provided AS IS and is not guaranteed to work perfectly in your environment. Testing is always a good idea. Any risk in running this script is entirely on you.
#
#******************************************

#******************************************
#
# Variable Definitions
#
#******************************************

$strSubject = "Lync User Report"
$strSMTPServer = "smtp.thatucguy.com"
$strToEmail = "lync.admin@thatucguy.com"
$strFromEmail = "no-reply@thatucguy.com"
# Registrar Pools
$poolAmericasFQDN = "lync-pool-americas.thatucguy.com"
$poolAmericas = "Americas Users"
$poolEMEAFQDN = "lync-pool-emea.thatucguy.com"
$poolEMEA = "EMEA Users"
# Conferencing Policies
$ConfSilver = "Lync-Conferencing-Silver"
$ConfGold = "Lync-Conferencing-Gold"
$ConfPlatinum = "Lync-Conferencing-Platinum"

#******************************************
#
# Load Required PS Modules
#
#******************************************

if ((Get-Module ActiveDirectory) -eq $null){Import-Module ActiveDirectory}
if ((Get-Module Lync) -eq $null){Import-Module Lync}

$blnDebug = $false

#********************************
#
# Get User counts, total and for each pool
#
#********************************

$counttotal = (Get-CsUser -OnLyncServer).count
$countamericas = (Get-CsUser -filter {registrarpool -eq $poolAmericasFQDN}).count
$countemea = (Get-CsUser -filter {registrarpool -eq $poolEMEAFQDN}).count
$usercount = $usercount + "

Lync User Report

" $usercount = $usercount + "" $usercount = $usercount + "
Total Users$poolAmericas$poolEMEA
$counttotal$countamericas$countemea
" #******************************** # # Get User counts by Conferencing Policy # #******************************** $countSilver = (Get-CsUser -filter {ConferencingPolicy -eq $ConfSilver}).count $countGold = (Get-CsUser -filter {ConferencingPolicy -eq $ConfGold}).count $countPlatinum = (Get-CsUser -filter {ConferencingPolicy -eq $ConfPlatinum}).count $ConfCount = $ConfCount + "

Lync User Report by Conferencing Policy

" $ConfCount = $ConfCount + "" $ConfCount = $ConfCount + "
Silver UsersGold UsersPlatinum Users
$countSilver$countGold$countPlatinum
" #******************************** # # Create and send email # #******************************** $strComputerName = gc env:computername $dtTimeNow = get-date $strScriptInfo = " Script Info Script Name: " + $MyInvocation.MyCommand.Definition + " Time: " + $dtTimeNow + " Run From: " + $strComputerName $strHTMLHeader = $strHTMLHeader + "" $strHTMLHeader = $strHTMLHeader + "" $strHTMLHeader = $strHTMLHeader + "" $strHTMLHeader = $strHTMLHeader + "" $strHTMLHeader = $strHTMLHeader + "" $strHTMLFooter = $strHTMLFooter + $strScriptInfo $strHTMLFooter = $strHTMLFooter + "" $strHTMLFooter = $strHTMLFooter + "" $strHTMLBody = $strHTMLHeader + $usercount + $ConfCount + $strHTMLFooter $msg = new-object Net.Mail.MailMessage $smtp = new-object Net.Mail.SmtpClient($strSMTPServer) $msg.From = $strFromEmail $strToEmail | foreach {$msg.To.Add($_)} $msg.subject = $strSubject $msg.IsBodyHtml = $true $msg.body = $strHTMLBody $smtp.Send($msg)

Hope this helps!

brad

Fun Fact:
Louisiana is the first state to have an Official Crustacean and it is the crawfish.

No comments:

Post a Comment