question

SC-2222 avatar image
0 Votes"
SC-2222 asked SC-2222 commented

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

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

windows-server-powershelloffice-exchange-server-administration
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@SC-2222
Could you tell us where do you see “DomainId” and why you need to get it?

There doesn't exist "DomainId" in Identity, so you will get such error:
201652-qa-kyle-10-22-21.png


0 Votes 0 ·

@SC-2222

Any update about this thread now? If this issue still exist, could you provide more detailed information to us for narrowing down this one?

0 Votes 0 ·

1 Answer

RichMatheisen-8856 avatar image
1 Vote"
RichMatheisen-8856 answered SC-2222 commented

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.

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Here is the screenshot
201499-result.png


0 Votes 0 ·
result.png (78.7 KiB)

I see an "Identity" property in the output, but it appears to be a string value. If that's the case it (the Identity property) won't have "DomainID" property. And if all that's true, then the "ToString()" method will fail.

0 Votes 0 ·
SC-2222 avatar image SC-2222 RichMatheisen-8856 ·

How can I get DomainID ?

0 Votes 0 ·
Show more comments