How do I use DSC to add a new local user to the local Administrators group?

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Daan Weda Daan Weda 1 month ago.

  • Author
    Posts
  • #38605
    Profile photo of Kiran
    Kiran
    Participant

    I'm using Windows Server 2012, PowerShell verion 4 and DSC 3.x.

    #earlier in the code I defined $ConfigData which worked with other configurations
    #earlier in the code I set PSDscAllowPlainTextPassword=$true
    ...
    Configuration CAdministrators {
    $syspass = ConvertTo-SecureString "securepassword" -AsPlainText -Force
    $mycreds = New-Object System.Management.Automation.PSCredential ("jdoe", $syspass)
    Node "fqdn" {
    Group CAdministrators {
    GroupName = 'Administrators'
    Ensure = 'Present'
    MembersToInclude = 'FQDN\jdoe' } } }
    CAdministrators -ConfigurationData $ConfigData

    #I know the user jdoe exists.

    I have made changes like 1) replacing MembersToInclude with Members 2) using localhost\userName instead of FQDN\userName 3) encapsulating the local user in parentheses 4) using the userName with no localhost nor an FQDN before it. These may have created the .mof file. But applying it fail. I am trying to run the .mof file to apply the configuration to the server that I am doing all the work on. To clarify, I am only using one server for this entire post's problem.

    I can successfully create the .mof with by running the .ps1 file with the configuration above. When I run start-dscconfiguration with the new .mof file, I get this error:

    "The PowerShell provider MSFT_GroupResource threw one or more non-terminating errors while running the Set-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details..
    The SendConfigurationApply function did not succeed..."

    How do I use DSC to add a new local user jdoe to the local Administrators group? As icing on the cake, how do I use the DependsOn stanza to make sure that the user already exists?

  • #56560
    Profile photo of Daan Weda
    Daan Weda
    Participant

You must be logged in to reply to this topic.