Powershell script to logoff user from all computers he is logged on to in domain (query domain controllers)
Hi,
I'm looking for a powershellscript which checks for a certain user AD user, then logs them off from all computers in the domain.
You can query domaincontroller logs for a user, then find the computer and execute a logoff. Why needed? His account is locked and he logged on to several devices, which locks the account again and again.
Had some kind of script, don't find it anymore.
Thanks!
PowershellActive Directory
Last Comment
janhoedt
8/22/2022 - Mon
janhoedt
ASKER
Thanks, that's the easy part, the logoff. Specifically need the part where I can see the computers to which a user is logged on.
Write-Host "Logging of $UserName with $SessionId from $Computer"
logoff $sessionId /server:$Computer
Write-Host "Checking if logoff was succesfull"
}
else {Write-Host "No sessionid found for $Username on $Computer"
}
}
}
else {Write-Output "Logoff Cancelled"}
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
Thanks, that's the easy part, the logoff.
Specifically need the part where I can see the computers to which a user is logged on.