Hi,
It sounds like you're encountering a 401 Unauthorized error when trying to generate a CSRF token for the System Center Operations Manager (SCOM) REST API.
Here's an example for your reference:
https://github.com/blakedrumm/SCOM-Scripts-and-SQL/blob/master/Powershell/SCOM-REST_API-Examples.ps1
If these steps don't resolve the issue, you might want to check for any specific configurations in your IIS or SCOM web console settings that could be affecting the token's lifetime or validity.