Logoff a Specific User from a Group of Remote Computers (PowerShell Script)


At times we get request on that we need to log off a particular user from multiple machines where he has remotely logged in forcefully. This scripts helps in doing the same. For a particular task I had written this and though would be helpful for others hence sharing.
It uses one input files $path1 = "c:\temp\servers.csv"   You can put the name of the servers or IP Address with line delimiter Like below and save it as servers.csv

SERVER1
SERVER 2
1.1.1.1
10.10.0.1 ...

Script
====================================

$username = 'Sudheesh'
$path1 = "c:\temp\servers.csv"
$Servers= Import-csv -path $path1 -Header  servername
foreach($Server1 in $Servers) {
$Server= $Server1.servername
$Server
$session = ((quser /server:$server | ? { $_ -match $username }) -split ' +')[2]
logoff $session /server:$server
}

Hope this Helps

Sudheesh Narayanaswamy

This posting /Script  is provided "AS IS" with no warranties and confers no rights


Comments (0)

Skip to main content