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

Pass empty string to parameter #1403

Closed HeKr09 closed 2 years ago

HeKr09 commented 2 years ago

I just wonder every time what happens to the ressources if you pass an empty string. I always use the same configuration for all environments. I am just changing the input parameters. For example:

$configData = Import-LocalizedData -FileName "parameters.psd1"
SharePoint -ConfigurationData $configData

My configuration looks somewhat like this:

Configuration SharePoint {
    Import-DscResource -ModuleName PSDesiredStateConfiguration
    Import-DscResource -ModuleName SharePointDSC -ModuleVersion 5.1.0
    $SharePointConfigData = $ConfigurationData.SharePoint

            SPFarm CreateOrJoinSharePointFarm {
                DatabaseServer            = $SharePointConfigData.DatabaseServerDefault
                AdminContentDatabaseName  = $SharePointConfigData.Farm.AdminContentDatabaseName
                FarmConfigDatabaseName    = $SharePointConfigData.Farm.FarmConfigDatabaseName
                ServerRole                = $Node.ServerRole
                Passphrase                = $SpPassphrase
                FarmAccount               = $SpFarmAccount
                CentralAdministrationPort = $SharePointConfigData.Farm.CentralAdministrationPort
                CentralAdministrationAuth = $SharePointConfigData.Farm.CentralAdministrationAuth
                RunCentralAdmin           = $Node.CentralAdmin
                IsSingleInstance          = "Yes"
                Ensure                    = "Present"
                DependsOn                 = @("[SPInstall]SharePointInstall", "[SqlAlias]$($SharePointConfigData.DatabaseServerDefault)")
                PsDscRunAsCredential      = $SpSetupAccount
            }
}

I wonder what happens when I want to pass the CentralAdministrationUrl? Can I use it this way so that the ressource doesn't use this value?

            SPFarm CreateOrJoinSharePointFarm {
                [...]
                CentralAdministrationPort = $SharePointConfigData.Farm.CentralAdministrationPort
                CentralAdministrationAuth = $SharePointConfigData.Farm.CentralAdministrationAuth
                CentralAdministrationUrl = $SharePointConfigData.Farm.CentralAdministrationUrl # This value would be empty: ""
                [...]
            }

This is just an example. Is there an answer to all ressources or does this differ between the ressources?

ykuijs commented 2 years ago

What you want is Splatting. Unfortunately, this is not possible with DSC resources 😢.

Gael Colas has created a blog post here in which he describes an alternative. This is what he is using in his Datum module. More information and examples on how to use this module can be found here.