Import-Module Lync
$LyncServer = "server1.domain.com"
$LogDatePartName = Get-Date -format 'yyyy_MM_dd'
$Log = "c:\scripts\"+$LogDatePartName+"_LyncEnabledUsers.csv"
get-csaduser | Where-Object {
$_.Enabled -ne $True -and
$_.WindowsEmailAddress -ne '' -and
$_.UserAccountControl -inotlike '*disabled*' -and
$_.DistinguishedName -inotlike '*impersonal*' -and
$_.IPPhone -ne ''
} | Select-Object UserPrincipalName | Export-Csv "$Log" -Delimiter ',' -NoTypeInformation
$LogSize = Get-ChildItem $Log
if ($LogSize.Length -ne '0') {
$UserFile = "$Log"
$MyData = Import-Csv $UserFile -Delimiter ','
ForEach ($item in $MyData){
$UserPrincipalName = $($item.UserPrincipalName)
Enable-CsUser $UserPrincipalName -RegistrarPool $LyncServer -SipAddressType EmailAddress
}
} else {
remove-item -path $Log -force
}