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
Anthony K O365Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
do you run this on PS3 or PS4, or is it still PS2? If you don't know, $PsVersionTable in PoweShell will tell you.
Anthony K O365Author Commented:
It is 4.0
Anthony K O365Author Commented:
Any thoughts from anyone on this Powershell error? Where is the null-value expression?

Thanks!
Are You Protected from Q3's Internet Threats?

Every quarter, WatchGuard's Threat Lab releases a security report that analyzes the top threat trends impacting companies around the world. For Q3, we saw that 6.8% of the top 100K websites use insecure SSL protocols. Read the full report to start protecting your business today!

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Oh, a simple typo! Your first line is missing the plural "s":
$errors = (get-msoluser -userprincipalName "username@contoso.com").Errors

Open in new window

Anthony K O365Author Commented:
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."
Anthony K O365Author Commented:
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
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
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

Anthony K O365Author Commented:
Here is what I got back:

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

Errors : {Microsoft.Online.Administration.ValidationError}

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

Name
----

----------------
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
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

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

Errors : {Microsoft.Online.Administration.ValidationError}
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
And the user you test with is displayed by the last query I posted, too?
Anthony K O365Author Commented:
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
----

----------------
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Ok, let's try again, What is the result of:
$errors = get-msoluser -userprincipalName "username@contoso.com" | Select -Expand 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anthony K O365Author Commented:
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
----

----------------
Anthony K O365Author Commented:
Excellent help! Thanks!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.