Closed Yvand closed 1 year ago
What error/exception are you getting? I am unable to reproduce the issue when running Import-Module SharePointServer -Verbose:$false
. I get the following warning, but no exception
PS C:\> Import-Module SharePointServer -Verbose:$false
WARNING: The names of some imported commands from the module 'SharePointServer' include unapproved verbs that might
make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the
Verbose parameter. For a list of approved verbs, type Get-Verb.
It really is the exception you see in the issue description:
[ERROR] You cannot call a method on a null-valued expression.
To reproduce it, you need to have a server with SharePoint Subscription 23H1, and that has never been joined to a farm (maybe it is enough that it is not member of a farm). I do not repro this error if the server is already joined to a farm.
Ah, check! That explains why I wasn't able to reproduce, I tested it on a farm joined to the farm 😉
My guess is that a change in the module has been implemented in 23H1 that tries to connect to the farm. Since the server hasn't been joined yet, it throws this error. By removing the explicit import, the module is only loaded on-demand further down the code and apparently the issue has been resolved.
Will merge the PR once the unit tests are done!
Problem description
Specifically in a VM with SharePoint Subscription + CU 23H1 installed, resource SPFarm throws an exception when creating the SharePoint farm. The exact same exception can be reproduced outside of SharePointDsc, by running the code below in a Windows PowerShell prompt:
The block below (set in in function
Invoke-SPDscCommand
) will cause the exception later, when runningInvoke-Command
:If I comment the block above, resource SPFarm creates the farm successfully and with no error
Verbose logs
DSC configuration
Suggested solution
It looks like the whole PowerShell module
SharePointServer
was removed starting with SharePoint Subscription 23H1, but I did not hear about it so I cannot guarantee that this is the root causeEDIT: I tested to never load module SharePointServer if it is SharePoint Subscription, and so far it worked with both SharePoint Subscription RTM and SharePoint Subscription 23H1, so it seems that an easy fix is to simply skip that for SharePoint Subscription. I'll submit a PR soon with this change and wait for your feedback on it
SharePoint version and build
Operating system the target node is running
PowerShell version and build the target node is running
SharePointDsc version