With the help of ChatGPT, after numerous attempts, I have managed to write the shortest code for self-elevating PowerShell permissions:
if (-not (net session)) { Start-Process powershell -WorkingDirectory $PSScriptRoot -ArgumentList "-File `"$PSCommandPath`"" -Verb RunAs; exit }