Created
October 1, 2020 17:15
-
-
Save michaellwest/6cfa73098e3ba6c38ce1d3ecd31c0383 to your computer and use it in GitHub Desktop.
Export and Import user access using Sitecore PowerShell Extensions
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
| # 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 |
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
| # 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