You cannot call a method on a null-valued expression in Exchange Management Shell 2019

SC 236 Reputation points
2022-05-12T10:47:14.293+00:00

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

  • $domain = (Get-DomainController).Identity.DomainId.ToString()
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidOperation: (:) [], RuntimeException
  • FullyQualifiedErrorId : InvokeMethodOnNull
Exchange | Exchange Server | Management
Windows for business | Windows Server | User experience | PowerShell
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2022-05-12T14:33:50.257+00:00

    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.