Created
July 28, 2019 08:50
-
-
Save johlju/304dcb68fd385e8b305f895ee2d27a9c to your computer and use it in GitHub Desktop.
Example creating 500 Active Directory test users with DSC
This file contains hidden or 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
$computersContainerDistinguishedName = (Get-ADDomain).ComputersContainer | |
if ($computersContainerDistinguishedName -match 'DC=.+') | |
{ | |
$domainDistinguishedName = $matches[0] | |
} | |
$ConfigurationData = @{ | |
AllNodes = @( | |
@{ | |
NodeName = 'localhost' | |
PsDscAllowPlainTextPassword = $true | |
DomainDistinguishedName = $domainDistinguishedName | |
UserNamePrefix = 'DscUser' | |
DisplayNamePrefix = 'Dsc User' | |
Password = New-Object ` | |
-TypeName System.Management.Automation.PSCredential ` | |
-ArgumentList @( | |
'AnyName', | |
(ConvertTo-SecureString -String 'P@ssW0rd1' -AsPlainText -Force) | |
) | |
AdministratorUserName = ('{0}\Administrator' -f $domainDistinguishedName) | |
AdministratorPassword = 'P@ssw0rd1' | |
} | |
) | |
} | |
Configuration MSFT_ADUser_Create500Users | |
{ | |
Import-DscResource -ModuleName 'ActiveDirectoryDsc' | |
node $AllNodes.NodeName | |
{ | |
1..500 | % { | |
ADUser ('MSFT_ADUser_CreateUser{0}_Config' -f $_) | |
{ | |
DomainName = $Node.DomainDistinguishedName | |
UserName = '{0}{1}' -f $Node.UserNamePrefix, $_ | |
UserPrincipalName = '{0}{1}' -f $Node.UserNamePrefix, $_ | |
DisplayName = '{0} {1}' -f $Node.DisplayNamePrefix, $_ | |
PasswordNeverExpires = $true | |
Password = $Node.Password | |
PasswordNeverResets = $true | |
DomainAdministratorCredential = New-Object ` | |
-TypeName System.Management.Automation.PSCredential ` | |
-ArgumentList @( | |
$Node.AdministratorUserName, | |
(ConvertTo-SecureString -String $Node.AdministratorPassword -AsPlainText -Force) | |
) | |
} | |
} | |
} | |
} | |
# ~26 seconds | |
Measure-Command -Expression { | |
MSFT_ADUser_Create500Users -OutputPath C:\DSCTest -ConfigurationData $ConfigurationData | |
} | |
# https://github.com/powershell/sharepointdsc/wiki/Error-Exceeded-the-configured-MaxEnvelopeSize-quota | |
Set-Item -Path WSMan:\localhost\MaxEnvelopeSizeKb -Value 2048 | |
# Create ~93 seconds | |
Measure-Command -Expression { | |
Start-DscConfiguration -Wait -Force -Path c:\DSCTest | |
} | |
# Enforce ~32 seconds | |
Measure-Command -Expression { | |
Start-DscConfiguration -Wait -Force -Path c:\DSCTest | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment