Lync Disable – AD Disabled users

Hi.

Have written a short powershell script that disables AD disabled Lync users.
This will prevent some warnings in Lync Eventlog.

Script changed with regards to some of the feedback.
Not changed with regards to the comment around Syntetic Transactions – Work in progress….


#####################################################################################
# Disable-AdDisabledCsUsers.ps1
#
# v1.0 - August 2012 by Trond Egil Gjelsvik-Bakke (trogjels.wordpress.com)
# v1.1 - October 2012
#        Changed script regarding to LogFile creation.
#
#
# Pulls all AD disabled users from AD and disables them for Lync as well
#
# Writes automatically to auto created logfile
# Can optionally write to screen using -verbose
#
# Example usage.
#
# .Disable-AdDisabledCsUsers.ps1 -verbose $true
#
####################################################################################
param($verbose)
Import-Module active*

#Create LogFile
$LogFile = "DisabledAdUsers-"+(Get-Date -uFormat %Y-%m-%d-%H%M%S)+".txt"
$LogTXT = "Processing Users.....`n"
Out-File -FilePath $LogFile -InputObject $LogTXT

$disabledADusers = Get-CsAdUser | ?{$_.UserAccountControl -match "AccountDisabled" -and $_.Enabled -eq $true}

Foreach ($user in $disabledADusers)
{
    $displayname = $user.FirstName + " " + $user.LastName
    
    #Disable-CSUser -Identity $identity
    if ($verbose -eq $true)
    {
        Write-Host "Disabled AD user $displayname is now disabled for Lync as well"
    }
    $LogTXT = "$displayname is disabled in AD, and now disabled for Lync"
    Out-File -FilePath $LogFile -InputObject $LogTXT -Append
}
Advertisements