PowerShell
Edit|Remove
##############################################################################################  
#                Author: Abhishek Gupta 
#                Date: 30/12/2015  
#                Desc: Find Active Directory Disabled but Lync Enabled Accounts 
###############################################################################################  
###################### Importing Lync Module ######################################## 
Import-Module Lync 
######################Define LOgs/ Variables#############################################  
$date = get-date -format d   
$date = $date.ToString().Replace(“/”, “-”)   
$time = get-date -format t   
$time = $time.ToString().Replace(":""-")   
$time = $time.ToString().Replace(" """)  
$output = ".\Logs" + "\"+ "AdDisabledLyncenabled_" + $date + "_.csv" 
$logs = ".\Logs" + "\" + "Powershell" + $date + "_" + $time + "_.txt" 
$SMTPServer = "SMTP SErver"   
$emailFrom = "DoNotReply@labtest.com"   
$emailTo = "abhishek.gupta3@labtest.com" 
#####################Adding Logging################################################## 
Start-Transcript -Path $logs 
#################Powershell Command to Find Active Directory Disabled but Lync Enabled Accounts ############################################  
Get-CsAdUser -ResultSize Unlimited | Where-Object {$_.UserAccountControl -match "AccountDisabled" -and $_.Enabled -eq $true| Select-Object Name,Enabled,SipAddress, ID | Export-csv $output -NoTypeInformation 
# Variable initializing to send mail  
$TXTFile = $output  
$subject = "Active Directory Disabled and Lync Enabled Accounts"   
$emailBody = "Active Directory Disabled and Lync Enabled Accounts"  
# Code to Send Mail   
Send-MailMessage -SmtpServer $SMTPServer -From $emailFrom -To $emailTo -Subject $subject -Body $emailBody -Attachment $TXTFile  
stop-transcript 
 
Hi Readers,Sharing a script that I  have written for Lync . Disabling AD accounts does not automatically disable Lync Accounts. If Lync Accounts have External access they Can Still Login into Lync from outside Environment as Lync uses certificate authentications and these certificates are for 180 days. These can Cause compliance issue . I am Sharing script to find those accounts.

Pre-requisites: Lync

 

Extract the Scripts and change below variables

 

SMTPServer = "SMTP SErver" 

$emailFrom = "DoNotReply@labtest.com" 

$emailTo = "abhishek.Gupta3@labtest.com" 

Create a folder Logs in the directory where you are launching script from. So as to save transcript logs & output

 

Run the batch file or schedule it to run on daily basis.

This script will also send a report in the email with attachment as shown below


 With below paramaters : SamAccountname, Enabled : True, SipAddress, OU details in CSV file


 

Please rate the script if you like the script

 


 

Regards,

Abhishek Gupta

TCS - Messaging & Collaboration