I want to share my scripts to deactivate RC users.
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