Link to home
Start Free TrialLog in
Avatar of Anthony K O365
Anthony K O365Flag for United States of America

asked on

PowerShell error Question

I'm running the following PS:

$errors = (get-msoluser -userprincipalName "username@contoso.com").Error


$errors | foreach-object {"`nService: "+ $_.ErrorDetail.Name.split("/")[0]; "Error Message: "+ $_.ErrorDetail.ObjectErrors.ErrorRecord.ErrorDescription}

I get the following error:

You cannot call a method on a null-valued expression.
At C:\Users\ValidationStatusError.ps1:3 char:27
+ $errors | foreach-object {"`nService: "+ $_.ErrorDetail.Name.split("/")[0]; "Err ...
+                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here is my source material: (What am I doing wrong?)

https://support.microsoft.com/en-us/kb/2741233
Avatar of Qlemo
Qlemo
Flag of Germany image

do you run this on PS3 or PS4, or is it still PS2? If you don't know, $PsVersionTable in PoweShell will tell you.
Avatar of Anthony K O365

ASKER

It is 4.0
Any thoughts from anyone on this Powershell error? Where is the null-value expression?

Thanks!
Oh, a simple typo! Your first line is missing the plural "s":
$errors = (get-msoluser -userprincipalName "username@contoso.com").Errors

Open in new window

As before and even after adding the 'S' , it is complaining about something in this expression    {"`nService:

Error says:  "You cannot call a method on a null-valued expression."
This is the exact error message:

You cannot call a method on a null-valued expression.
At C:\Users\findErrors.ps1:2 char:27

+ $errors | foreach-object {"`nService: "+ $_.ErrorDetail.Name.split("/")[0]; "Err ...
+                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
I'm sorry, but since I cannot try myself, I cannot be that much helpful. We'll have to do some troubleshooting, so try this please, and post the results:
$errors = get-msoluser -userprincipalName "username@contoso.com" | Select Errors
Write-Host "errors count: $($errors.Count)"
Write-Host "----------------"
$errors | select -First 1 | fl *
Write-Host "----------------"
$errors | select -First 1 ErrorDetail | select Name
Write-Host "----------------"

Open in new window

Here is what I got back:

PS C:\Users\O 365 items> .\ErrorDetail.ps1
errors count:
----------------

Errors : {Microsoft.Online.Administration.ValidationError}

----------------

Name
----

----------------
IIUC, there is no error for that user object, and that is causing that error message. Are you certain there should be an error message for that user? Check with
Get-MsolUser | Where {$_.Errors –ne $null} | Select ObjectID, DisplayName

Open in new window

While using my online account, next to Errors, I see nothing, but this user shows this:

Errors : {Microsoft.Online.Administration.ValidationError}
And the user you test with is displayed by the last query I posted, too?
Here is another user from query:

PS C:\Users\O 365 items> .\ErrorDetail.ps1

errors count:
----------------

Errors : {Microsoft.Online.Administration.ValidationError, Microsoft.Online.Administration.ValidationError,
         Microsoft.Online.Administration.ValidationError}

----------------

Name
----

----------------
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is better! Excellent. Now I need to figure out  the 'ServiceInstance'  error.

PS C:\Users\O 365 items> .\ErrorDetail.ps1
errors count: 1
----------------


ExtensionData   : System.Runtime.Serialization.ExtensionDataObject
ErrorDetail     : ServiceInstance
Resolved        : False
ServiceInstance : MicrosoftCommunicationsOnline/NOAM-0B-A
Timestamp       : 7/2/2015 2:34:07 PM

----------------

Name
----

----------------
Excellent help! Thanks!!