Public/Revoke-AdminRights.ps1

function Revoke-AdminRights {
  <#
  .SYNOPSIS
    Revokes administrator rights on a remote computer.
  .DESCRIPTION
    Sends a request to the Make Me Admin service running on a remote computer to remove administrator rights from the current user.
  .PARAMETER HostName
    The name or IP address of the remote computer.
  .PARAMETER Reason
    The reason for removing administrator rights. Valid values: Timeout, Logoff, Manual, ServiceStop.
  .PARAMETER Port
    The port number where the Make Me Admin service is listening. Default is 3000.
  .EXAMPLE
    Revoke-AdminRights -HostName "SERVER01" -Reason Manual
    Manually revokes administrator rights on SERVER01.
  #>

  [CmdletBinding(SupportsShouldProcess = $true)]
  param(
    [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
    [ValidateNotNullOrEmpty()]
    [string]$HostName,

    [Parameter(Mandatory = $true, Position = 1, ValueFromPipelineByPropertyName = $true)]
    [RemovalReason]$Reason,

    [Parameter(Position = 2, ValueFromPipelineByPropertyName = $true)]
    [int]$Port = 3000
  )

  process {
    if ($PSCmdlet.ShouldProcess($HostName, "Revoke administrator rights with reason: $Reason")) {
      try {
        $result = [RemoteAdminRequestClient]::RevokeAdminRights($HostName, $Reason, $Port)
        if ($result) {
          Write-Host "Successfully revoked administrator rights on $HostName" -ForegroundColor Green
        }
        return $result
      } catch {
        Write-Error -Message $_.Exception.Message -ErrorId 'AdminRightsRevokeFailed' -Category InvalidOperation -TargetObject $HostName
        return $false
      }
    }
  }
}