Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Created July 15, 2019 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellwest/3190b8cfc537498f02d9532bedca4794 to your computer and use it in GitHub Desktop.
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.
# 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