Pages

Tuesday, July 9, 2013

How to implement reporting for a Lync account

I had a strange requirement from one of my client. He wanted to see Lync conferencing policy change on an account!
If the policy is changed then he would like to have mail send to him with the information and the check should happen every one hour. Checking every one hour and reporting it when ever policy change was a nightmare for my Operations team and i thought of automating it by using a powershell script :)
First you have to create a file with current information which can be used for comparing the status of policy.

#import the moudule
Import-Module 'C:\Program Files\Common Files\Microsoft Lync Server 2013\Modules\Lync\Lync.psd1'
#Below line will create a file which can be used for comparing. You have to change the sip address with the username which you are going run it. 
Get-CsUser sip:user@domain.com |select-object Identity, ConferencingPolicy |Export-csv D:\Scripts\AccountMonitoring\Default.csv -NoTypeInformation

Now create a news .ps1 file and schedule the same using schedule task. Here is the code, you have to change the user information with your account and domain.

#Import the Lync module
Import-Module 'C:\Program Files\Common Files\Microsoft Lync Server 2013\Modules\Lync\Lync.psd1'
#Get current policy which is assigned to the user to a file
Get-CsUser sip:user@domain.com |select-object Identity, ConferencingPolicy |Export-csv D:\Scripts\AccountMonitoring\Latest.csv -NoTypeInformation
#give the time to create the file
Sleep 60
#Creating the message which should be send in case there is a change.
$action = "Plase note that Conferencing Policy on account 'account@domain.com' has been changed, so request you to verify the configuration."
#Compare the files
compare-object -referenceobject $(get-content D:\Scripts\AccountMonitoring\default.csv) -differenceobject $(get-content D:\Scripts\LMSAccountMonitoring\latest.csv) |Export-Csv -Path D:\Scripts\AccountMonitoring\Output.csv -NoTypeInformation
$output = Get-Content D:\Scripts\AccountMonitoring\Output.csv
if ($output -eq $null)
    {exit 0}
else
    {
    $smtpServer = "smtp.dmain.com"
    $smtpFrom = "SAccountReporting@domain.com"
    $smtpTo = "prajeesh@domain.com"
    $messageSubject = "Change On Account Policy"
    $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
    $message.Subject = $messageSubject
    $message.IsBodyHTML = $true

    $message.Body = $message.Body + $action

    $smtp = New-Object Net.Mail.SmtpClient($smtpServer)
    $smtp.Send($message)
    }

No comments:

Post a Comment