Forum Discussion

iCer19's avatar
iCer19
Copper Contributor
Aug 09, 2022

Object reference not set to an instance of an object - when splatting to a custom function

I've written a module for a specific O365 function - onboarding users to mobile in InTune.   The module works, but I needed to add the ability for users to specify alternative credentials to run th...
  • LainRobertson's avatar
    Aug 09, 2022

    iCer19 

     

    We can't really give you any definitive answers here as there's not enough information.

     

    We'd need to know which line the error is referring to at a minimum, and if that error line is not in the example below, we'd need that area included.

     

    All I can infer from the example is:

     

    1. It is not possible for Params to be null, since even if $User is null, a key will be added named "User" for which the corresponding object will be a null reference;
    2. It is possible for the "Credential" key to not be added to the hashtable but not possible for it to be null if it is added.

     

    Still, without concise error information, that doesn't help much.

     

    Prior to calling your custom Get-EXOEnabled function, you could simply dump the $Params to output for confirmation.

     

    I'm not connected to Exchange at the moment but here's a "similar enough" example using a user from Azure AD instead. This shows I have two members in the hashtable, i.e. neither entry is null.

     

     

    If you find the same then the issue is likely something within your function, not the example you've provided in here. But again, this is still an assumption as there's not enough code and only an imprecise error to work from.

     

    Cheers,

    Lain

Share

Resources