$DisableUserSubmitButton.Add_Click({
$userAD = $UserInput.Text
$adinfo = $null
$adinfo = GetADProp
$adproperties = $adinfo.Userinfo
$adminname = $adproperties.GivenName
if($disableuserTextbox.Text -eq "")
{
$AddCommentLabelm2.Text = ""
$AddCommentLabelm2.Font = [System.Drawing.Font]::new("Cambria",9)
$AddCommentLabelm2.ForeColor= "DarkGray"
$AddCommentLabelm2.Text = "Enter username....!"
}
else
{
$username = $null
$user = $null
$Userattributes=$null
$AddCommentLabelm2.Text = ""
$AddCommentLabelm2.Font = [System.Drawing.Font]::new("Cambria",9)
$AddCommentLabelm2.ForeColor= "DarkGray"
$AddCommentLabelm2.Text = "Processing...."
$username = $disableuserTextbox.Lines
foreach($user in $username)
{
$Userattributes = Get-OPCsUser $user
If($Userattributes -eq $null)
{
$AddCommentLabelm2.Text = ""
$AddCommentLabelm2.Font = [System.Drawing.Font]::new("Cambria",9)
$AddCommentLabelm2.ForeColor= "DarkRed"
$AddCommentLabelm2.Text = "$user Invalid username..!"
Write-Output "$user :Invalid username..!,processed by $adminname" | Out-File -FilePath .\disabledusers.txt -Append
}
Else
{
If($Userattributes.RegistrarPool -eq $null)
{
try{
$AddCommentLabelm2.Text = ""
$AddCommentLabelm2.Font = [System.Drawing.Font]::new("Cambria",9)
$AddCommentLabelm2.ForeColor= "DarkBlue"
$AddCommentLabelm2.Text = "$user :User is on teams only mode, disable manually,processed by $adminname"
Write-Output "$user :User is on teams only mode, disable manually,processed by $adminname" | Out-File -FilePath .\disabledusers.txt -Append
# EmailRecordingenabled
}
catch
{
$AddCommentLabelm2.Text = ""
$AddCommentLabelm2.Font = [System.Drawing.Font]::new("Cambria",9)
$AddCommentLabelm2.ForeColor= "DarkBlue"
$AddCommentLabelm2.Text = "Session expired, please re-open the console"
}
# ClearAllModules
}
Else
{
If($Userattributes.Enabled -eq $true)
{
try
{
$error.clear()
$usersip= $Userattributes.sipaddress -replace ".*:"
Set-OPCsUser $user -enabled $false -SipAddress "sip:Disabled_$usersip"
Revoke-OPCsClientCertificate $user
#Grant-csTeamsmeetingpolicy $user -policyname "Tag:Aud_Vid_Rec_AppSh_On_Dial_In"
$AddCommentLabelm2.Text = ""
$AddCommentLabelm2.Font = [System.Drawing.Font]::new("Cambria",9)
$AddCommentLabelm2.ForeColor= "DarkGreen"
$AddCommentLabelm2.Text = "$user :User has been disabled, processed by $adminname"
Write-Output "$user :User has been disabled,processed by $adminname" | Out-File -FilePath .\disabledusers.txt -Append
#EmailRecordingenabled
}
Catch
{
Write-host $error[0]
$AddCommentLabelm2.Text = ""
$AddCommentLabelm2.Font = [System.Drawing.Font]::new("Cambria",9)
$AddCommentLabelm2.ForeColor= "DarkGreen"
$AddCommentLabelm2.Text = "$user : User has been disablement failed, processed by $adminname"
Write-Output "$user :User has been disablement failed,processed by $adminname" | Out-File -FilePath .\disabledusers.txt -Append
}
}
else
{
$AddCommentLabelm2.Text = ""
$AddCommentLabelm2.Font = [System.Drawing.Font]::new("Cambria",9)
$AddCommentLabelm2.ForeColor= "DarkBlue"
$AddCommentLabelm2.Text = "$user :User is already disabled,processed by $adminname"
Write-Output "$user :User is already disabled, processed by $adminname" | Out-File -FilePath .\disabledusers.txt -Append
}
}
}
Start-Sleep -Seconds 2}
}
})