Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created December 1, 2014 20:29
Show Gist options
  • Save guitarrapc/6c6d19ce31d4f92f269c to your computer and use it in GitHub Desktop.
Save guitarrapc/6c6d19ce31d4f92f269c to your computer and use it in GitHub Desktop.
PowerShell DSC Advent Calendar 2014 : Day 2 なぜ Configuration Management が必要なのか : http://tech.guitarrapc.com/entry/2014/12/02/062659 // Add User DSC Configuraion Sample https://github.com/guitarrapc/DSCSample/blob/master/PowerShellDSCAdventCalendar/2014/Day2_WhyConfiuguraitonMangementToolIsRequired/UserByConfiguration.ps1
configuration UserAndGroup
{
param
(
[parameter(Mandatory = 1)]
[PSCredential[]]$credential,
[parameter(Mandatory = 0)]
[string]$Group = "Administrators"
)
foreach ($x in $credential)
{
User $x.UserName
{
UserName = $x.UserName
Ensure = "Present"
Password = $x
PasswordNeverExpires = $true
PasswordChangeNotAllowed = $true
}
Group $x.UserName
{
GroupName = $Group
Ensure = "Present"
MembersToInclude = $x.UserName
DependsOn = "[User]{0}" -f $x.UserName
}
}
}
$path = "d:\UserAndGroup"
UserAndGroup -OutputPath $path -credential (Get-Credential)
Start-DscConfiguration -Wait -Force -Verbose -Path $path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment