Created
December 1, 2014 20:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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