Public/Invoke-AdminRightsRequest.ps1

function Invoke-AdminRightsRequest {
  <#
  .SYNOPSIS
    Requests administrator rights on a remote computer.
  .DESCRIPTION
    Sends a request to the Make Me Admin service running on a remote computer to grant administrator rights to the current user.
  .PARAMETER HostName
    The name or IP address of the remote computer.
  .PARAMETER Port
    The port number where the Make Me Admin service is listening. Default is 3000.
  .EXAMPLE
    Invoke-AdminRightsRequest -HostName "SERVER01"
    Requests administrator rights on SERVER01.
  #>

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

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

  process {
    if ($PSCmdlet.ShouldProcess($HostName, "Request administrator rights")) {
      try {
        $result = [RemoteAdminRequestClient]::RequestAdminRights($HostName, $Port)
        if ($result) {
          Write-Host "Successfully requested administrator rights on $HostName" -ForegroundColor Green
        }
        return $result
      } catch {
        Write-Error -Message $_.Exception.Message -ErrorId 'AdminRightsRequestFailed' -Category InvalidOperation -TargetObject $HostName
        return $false
      }
    }
  }
}