Forum Discussion
Object reference not set to an instance of an object - when splatting to a custom function
- Aug 09, 2022
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:
- 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;
- 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
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:
- 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;
- 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