Created
July 15, 2019 18:53
-
-
Save michaellwest/3190b8cfc537498f02d9532bedca4794 to your computer and use it in GitHub Desktop.
Remove duplicate user sessions during login using Sitecore PowerShell Extensions. Solution for https://github.com/SitecoreSupport/Sitecore.Support.94909.
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
# Solution for https://github.com/SitecoreSupport/Sitecore.Support.94909 | |
# Cannot login in Sitecore CMS due to multiple same users already logged in | |
# Saved to /sitecore/system/Modules/PowerShell/Script Library/[CUSTOM_MODULE_NAME]/Pipelines/LoggedIn/Remove Multiple Sessions | |
$pipelineArgs = Get-Variable -Name pipelineArgs -ValueOnly | |
$username = $pipelineArgs.UserName | |
if(!$username) { return } | |
$sessionId = [System.Web.HttpContext]::Current.Session.SessionID | |
Write-Log "The current session Id is $($sessionId) for user $($username)" | |
$availableSessions = Get-Session | Where-Object { $_.Username -eq $username} | |
foreach($session in $availableSessions) { | |
if($session.SessionId -eq $sessionId) { continue } | |
Write-Log "Removing duplicate session $($session.SessionId) for user $($username)" | |
$session | Remove-Session | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment