dsccommunity / SharePointDsc

The SharePointDsc PowerShell module provides DSC resources that can be used to deploy and manage a SharePoint farm
MIT License
245 stars 107 forks source link

[SPShellAdmins] Get-SPDatabase cmdlet cannot be found #1411

Closed ykuijs closed 1 year ago

ykuijs commented 1 year ago

Problem description

The SPShellAdmins resource is calling the function "Get-SPDscDatabaseOwnerList". This function is executing this command:

$sqlInstances = (Get-SPDatabase -Verbose:$false).NormalizedDataSource | Sort-Object | Get-Unique

However, the SharePoint snapin isn't available at that time, resulting in the following error:

PowerShell DSC resource MSFT_SPShellAdmins failed to execute Test-TargetResource functionality with error message: The term 'Get-SPDatabase' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. "},

Verbose logs

N/A

DSC configuration

N/A

Suggested solution

In MSFT_SPShellAdmins.psm1 replace

$databaseOwners = Get-SPDscDatabaseOwnerList

with

$sqlInstances = (Get-SPDatabase -Verbose:$false).NormalizedDataSource | Sort-Object | Get-Unique
$databaseOwners = Get-SPDscDatabaseOwnerList -sqlInstances $sqlInstances

and in SPShellAdmin.psm1 replace

   param ( )

    $sqlInstances = (Get-SPDatabase -Verbose:$false).NormalizedDataSource | Sort-Object | Get-Unique

with

   param ( $sqlInstances )

    #$sqlInstances = (Get-SPDatabase -Verbose:$false).NormalizedDataSource | Sort-Object | Get-Unique

SharePoint version and build

SP2019

Operating system the target node is running

Windows Server 2016

PowerShell version and build the target node is running

5.1

SharePointDsc version

v5.2