Toying with DSC. Here is some code to add a user to a local administrators group via DSC. Use at your own risk. Marginally tested (works on my machine…).
cls configuration UserConfig{ param( [System.Management.Automation.PSCredential]$DomainCredential ) Import-DscResource -ModuleName PSDesiredStateConfiguration node $AllNodes.NodeName{ Group Admin{ GroupName = 'Administrators' Ensure = 'Present' #PsDscRunAsCredential = $mycreds Credential = $DomainCredential Members = @('domainname\username') } } } $configData = @{ AllNodes = @( @{ NodeName = 'SEAPR1DBBAT046' PSDscAllowPlainTextPassword = $true PSDscAllowDomainUser = $true } ) } $cred = Get-Credential -UserName domain\user -Message "Password please" UserConfig -DomainCredential $cred -ConfigurationData $configData
You should use MembersToInclude rather than Members. By using Members you will remove any other users in your Administrators group not listed in your configuration. By using MembersToInclude, you’ll only add the users listed.
https://github.com/PowerShell/PSDscResources#group
Good tip. I’ll drop it in. I’ve not touched dsc since this post I think.