Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jammykam
Last active April 4, 2022 18:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jammykam/74412aa261be522c5d2027f53b625f6d to your computer and use it in GitHub Desktop.
Save jammykam/74412aa261be522c5d2027f53b625f6d to your computer and use it in GitHub Desktop.
Create Users and Add to specified roles from CSV file using Sitecore PowerShell Extensions
$VerbosePreference = "Continue"
$newUsersFile = Receive-File -Path "C:\temp\upload" -CancelButtonName "No, I will do it using MS Excel instead"
$newUsers = Import-Csv -Path $newUsersFile
foreach($user in $newUsers) {
Write-Verbose "Creating User: $($user.Username)"
New-User -Identity $($user.Username) -Enabled -Password $($user.Password) -Email $($user.Email) -FullName "$($user.Name)"
$($user.Roles).Split(",") | ForEach {
Write-Verbose "Adding user to role: $_ "
Add-RoleMember -Identity $_ -Members "$($user.Username)"
}
}
Name Username Password Email Roles
Jammy KamSir jammykam real jammykam@worldofunicorns.com Author,Developer
Fake Kam kamsar fake kam@fullysynthetic.com Developer,Experience Explorer
Real Unicorn Guy unicornguy B4D455 unicorn@jammykamsar.com Sitecore Local Administrators
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment