Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Created October 1, 2020 17:15
Show Gist options
  • Select an option

  • Save michaellwest/6cfa73098e3ba6c38ce1d3ecd31c0383 to your computer and use it in GitHub Desktop.

Select an option

Save michaellwest/6cfa73098e3ba6c38ce1d3ecd31c0383 to your computer and use it in GitHub Desktop.
Export and Import user access using Sitecore PowerShell Extensions
# Use this report to export current access
$users = Get-User -Filter * | Where-Object { $_.Roles.Count -gt 0 }
$records = [System.Collections.ArrayList]@()
foreach($user in $users) {
$record = [PSCustomObject]@{
"Username" = $user.Name
"Roles" = ($user.Roles | Select-Object -ExpandProperty Name) -join ","
}
$records.Add($record) > $null
}
$records | Show-ListView
# Use this to import the report
$path = Receive-File -Path $SitecoreTempFolder
if ((Test-Path -Path $path)) {
$records = Import-Csv -Path $path
foreach($record in $records) {
Write-Host "Adding user $($record.Username)"
if((Get-User -Id $record.Username -ErrorAction 0)) {
$roles = $record.Roles -split ","
foreach($role in $roles) {
Write-Host " - $($role)"
Add-RoleMember -Id $role -Member $record.Username
}
} else {
Write-Host " - User has not logged in before"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment