Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlRole resource incorrect documentation or bug #1592

Closed
since81 opened this issue Jul 10, 2020 · 6 comments · Fixed by #1597
Closed

SqlRole resource incorrect documentation or bug #1592

since81 opened this issue Jul 10, 2020 · 6 comments · Fixed by #1597
Labels
bug The issue is a bug.

Comments

@since81
Copy link

since81 commented Jul 10, 2020

Details of the scenario you tried and the problem that is occurring

I am trying to add new users to the role, but got:
Failed to invoke DSC Test method: Cannot validate argument on parameter 'ServerName'. The argument is null or empty. Provide an argument that is not null or empty and then try the command again.

Verbose logs showing the problem

Suggested solution to the issue

in documentation ServerName is not mandatory

The DSC configuration that is used to reproduce the issue (as detailed as possible)

{
    "changed": false,
    "invocation": {
        "module_args": {
            "PsDscRunAsCredential_password": null,
            "ServerRoleName": "sysadmin",
            "module_version": "latest",
            "MembersToExclude": null,
            "DependsOn": null,
            "InstanceName": "TEST",
            "resource_name": "SqlRole",
            "Ensure": "Present",
            "ServerName": null,
            "PsDscRunAsCredential_username": null,
            "Members": null,
            "MembersToInclude": [
                "DOMAIN\\Administrator",
                "DOMAIN\\SQLACL-SysAdmin"
            ]
        }
    }
}

SQL Server edition and version the target node is running

Microsoft SQL Server 2017 (RTM-CU20) (KB4541283) - 14.0.3294.2 (X64) Mar 13 2020 14:53:45 Copyright (C) 2017 Microsoft Corporation Developer Edition (64-bit) on Windows Server 2019 Standard 10.0 (Build 17763: ) (Hypervisor)

SQL Server PowerShell modules present on the target node

Name Version Path


SQLPS 14.0 C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules\SQLPS\SQLPS.psd1

The operating system the target node is running

OsName : Microsoft Windows Server 2019 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture : 64-bit
WindowsVersion : 1809
WindowsBuildLabEx : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage : en-US
OsMuiLanguages : {en-US}

Version and build of PowerShell the target node is running

Name Value


PSVersion 5.1.17763.1007
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.1007
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Version of the DSC module that was used

Name Version Path


SqlServerDsc 14.0.0 C:\Program Files\WindowsPowerShell\Modules\SqlServerDsc\14.0.0\SqlServerDsc.psd1
SqlServerDsc 13.0.0.0 C:\Program Files\WindowsPowerShell\Modules\SqlServerDsc\13.0.0.0\SqlServerDsc.psd1

@johlju
Copy link
Member

johlju commented Jul 10, 2020

ServerName is not mandatory but if used in the configuration it must be set to a valid value. If you don't need to set a value for ServerName then the parameter should be left out of the configuration.

@johlju johlju added needs more information The issue needs more information from the author or the community. waiting for author response The pull request is waiting for the author to respond to comments in the pull request. and removed needs more information The issue needs more information from the author or the community. labels Jul 10, 2020
@cmcapellan
Copy link
Contributor

I am having the exact same problem using the 14.1 version, in my case I have not specified ServerName and I am getting the same error.

Here is the relevant part of my code:

        {
            Name                 = 'BUILTIN\Administrators'
            LoginType            = 'WindowsUser'
            InstanceName         = 'MSSQLSERVER'
        }
        SqlRole 'Grant_sysadmin_for_LocalAdmins'
        {
            ServerRoleName       = 'sysadmin'
            MembersToInclude     = 'BUILTIN\Administrators'
            InstanceName         = 'MSSQLSERVER'
            DependsOn            = '[SqlLogin]AllowLoginForLocalAdmins'
        }

And I am getting the result:

"Exception":  {
                      "Message":  "The PowerShell DSC resource \u0027[SqlRole]Grant_sysadmin_for_LocalAdmins\u0027 with SourceInfo \u0027::35::9::SqlRole\u0027 threw one or more non-terminating errors while running the Test-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.",
                      "Data":  {

                               },
                      "InnerException":  {
                                             "Message":  "Cannot validate argument on parameter \u0027ServerName\u0027. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.",
                                             "ParameterName":  "ServerName",
                                             "ParameterType":  "string",
                                             "TypeSpecified":  "string",
                                             "ErrorId":  "ParameterArgumentValidationError",
                                             "Line":  432,
                                             "Offset":  51,
                                             "CommandInvocation":  "System.Management.Automation.InvocationInfo",
                                             "ErrorRecord":  "Cannot validate argument on parameter \u0027ServerName\u0027. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.",
                                             "WasThrownFromThrowStatement":  false,
                                             "Data":  "System.Collections.ListDictionaryInternal",

@cmcapellan
Copy link
Contributor

One more note, I tried adding "$env:COMPUTERNAME" (with both single and double quotes), but as I am using Azure DSC, it gets populated with "CLIENT" in the compile step. So unforunately not sure if I can find a workaround. Have been using a bunch of other modules, including SqlLogin, SqlDatabaseDefaultLocation, SqlMemory, SqlConfiguraton with no issues so far, just SqlRole having this ServerName issue.

@cmcapellan
Copy link
Contributor

I see the problem, SqlRole uses $PSBoundParameters which doesn't work with default values, I see this was fixed in other places in issue #1503 but it seems like this one was missed.

johlju pushed a commit that referenced this issue Jul 22, 2020
- SqlRole
  - Fixed the ServerName parameter to work with default value of
    $env:COMPUTERNAME (issue #1592).
@johlju
Copy link
Member

johlju commented Jul 22, 2020

@cmcapellan Great catch!

@johlju johlju added bug The issue is a bug. and removed waiting for author response The pull request is waiting for the author to respond to comments in the pull request. labels Jul 22, 2020
@johlju
Copy link
Member

johlju commented Jul 22, 2020

I will release a new version tomorrow that will fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug.
Projects
None yet
3 participants