# LDAP Auth - Disabled AD Users

**URL:** <https://forums.rocket.chat/t/ldap-auth-disabled-ad-users/1715>\
**Category:** Community Support\
**Created:** [July 30, 2018, 4:06pm UTC](https://forums.rocket.chat/t/ldap-auth-disabled-ad-users/1715 "2018-07-30T16:06:33Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![anton.karlan](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/anton.karlan/32/1347_2.png) [@anton.karlan](https://forums.rocket.chat/u/anton.karlan)\
**Post date:** [May 8, 2020, 5:06am UTC](https://forums.rocket.chat/t/ldap-auth-disabled-ad-users/1715/11 "2020-05-08T05:06:06Z")

</div>

I want to share my scripts to deactivate RC users.

```auto
function Get-RCUserId
{
	param(
		    [Parameter(Mandatory=$True)][string]$Username
	)
    $username = $username.ToLower().Trim()
    $Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $Headers.Add("X-Auth-Token", 'token')
    $Headers.Add("X-User-ID", 'userId')
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    $url = "https://rc.company.com/api/v1/users.info?username=" + $username
    
    try {
        $Response = Invoke-RestMethod -Headers $Headers $url -Method Get -ContentType 'application/json'
        $result = $Response.user._id
    } catch {
        $result = $_.Exception
    }
                 
    return $result
}

function Disable-RCUser
{
	param(
		    [Parameter(Mandatory=$True)][string]$userId
	)

    $Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $Headers.Add("X-Auth-Token", 'token')
    $Headers.Add("X-User-ID", 'userId')
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    $body = @{
        userId = $userId
        data = @{ "active" = $false }
    }
    $body = $body | ConvertTo-Json -Depth 2
    try {
        $DisableResponse = Invoke-RestMethod -Headers $Headers "https://rc.company.com/api/v1/users.update" -Method Post -Body $body -ContentType 'application/json'             
        $result = $DisableResponse.success
    } catch {
        $result = $_.Exception
    }
    return $result
}

$UsertoDisable = Get-RCUserId -Username "TestUser"
Disable-RCUser -userId $UsertoDisable

```

---

_[View the full topic](https://forums.rocket.chat/t/ldap-auth-disabled-ad-users/1715)._
