What results do you get if you simply run Get-DomainController?
The error is telling you that the cmdlet returned a value of $null instead of the domain controller object(s) you expected.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am not able to execute the following command in Exchange Management Shell 2019. It returns the error as "you cannot call a method on a null-valued expression"
[PS] C:\>$domain = (Get-DomainController).Identity.DomainId.ToString()
You cannot call a method on a null-valued expression.
At line:1 char:1
What results do you get if you simply run Get-DomainController?
The error is telling you that the cmdlet returned a value of $null instead of the domain controller object(s) you expected.