Your script works, just update the last content type to application/json:
Invoke-RestMethod -Uri $adoTaskUri -ContentType "application/json" -Body $body -headers $adoHeader -Method POST
PATCH is used to update a team project: https://docs.microsoft.com/en-us/rest/api/azure/devops/core/projects/update?view=azure-devops-rest-6.1
The issue is that you can't reference the changed value in the same task.
I created a new Powershell task and just called Write-Host "env:IP environment variable set to ($env:IP)" which output the IP address correctly.
I'm not familiar with Invoke-Build, but appearantly it's a part of the InvokeBuild PowerShell module? In that case, you'll have to install the module as part of the script where you're using it. Your YAML should be something like this:
- stage: Build
- job: Build
- task: PowerShell@2