Anthony K O365
asked on
PowerShell error Question
I'm running the following PS:
$errors = (get-msoluser -userprincipalName "username@contoso.com").Er ror
$errors | foreach-object {"`nService: "+ $_.ErrorDetail.Name.split( "/")[0]; "Error Message: "+ $_.ErrorDetail.ObjectError s.ErrorRec ord.ErrorD escription }
I get the following error:
You cannot call a method on a null-valued expression.
At C:\Users\ValidationStatusE rror.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
$errors = (get-msoluser -userprincipalName "username@contoso.com").Er
$errors | foreach-object {"`nService: "+ $_.ErrorDetail.Name.split(
I get the following error:
You cannot call a method on a null-valued expression.
At C:\Users\ValidationStatusE
+ $errors | foreach-object {"`nService: "+ $_.ErrorDetail.Name.split(
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
Here is my source material: (What am I doing wrong?)
https://support.microsoft.com/en-us/kb/2741233
do you run this on PS3 or PS4, or is it still PS2? If you don't know, $PsVersionTable in PoweShell will tell you.
ASKER
It is 4.0
ASKER
Any thoughts from anyone on this Powershell error? Where is the null-value expression?
Thanks!
Thanks!
Oh, a simple typo! Your first line is missing the plural "s":
$errors = (get-msoluser -userprincipalName "username@contoso.com").Errors
ASKER
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."
Error says: "You cannot call a method on a null-valued expression."
ASKER
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
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(
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ 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 "----------------"
ASKER
Here is what I got back:
PS C:\Users\O 365 items> .\ErrorDetail.ps1
errors count:
----------------
Errors : {Microsoft.Online.Administ ration.Val idationErr or}
----------------
Name
----
----------------
PS C:\Users\O 365 items> .\ErrorDetail.ps1
errors count:
----------------
Errors : {Microsoft.Online.Administ
----------------
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
ASKER
While using my online account, next to Errors, I see nothing, but this user shows this:
Errors : {Microsoft.Online.Administ ration.Val idationErr or}
Errors : {Microsoft.Online.Administ
And the user you test with is displayed by the last query I posted, too?
ASKER
Here is another user from query:
PS C:\Users\O 365 items> .\ErrorDetail.ps1
errors count:
----------------
Errors : {Microsoft.Online.Administ ration.Val idationErr or, Microsoft.Online.Administr ation.Vali dationErro r,
Microsoft.Online.Administr ation.Vali dationErro r}
----------------
Name
----
----------------
PS C:\Users\O 365 items> .\ErrorDetail.ps1
errors count:
----------------
Errors : {Microsoft.Online.Administ
Microsoft.Online.Administr
----------------
Name
----
----------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.Serializati on.Extensi onDataObje ct
ErrorDetail : ServiceInstance
Resolved : False
ServiceInstance : MicrosoftCommunicationsOnl ine/NOAM-0 B-A
Timestamp : 7/2/2015 2:34:07 PM
----------------
Name
----
----------------
PS C:\Users\O 365 items> .\ErrorDetail.ps1
errors count: 1
----------------
ExtensionData : System.Runtime.Serializati
ErrorDetail : ServiceInstance
Resolved : False
ServiceInstance : MicrosoftCommunicationsOnl
Timestamp : 7/2/2015 2:34:07 PM
----------------
Name
----
----------------
ASKER
Excellent help! Thanks!!