PoshCode Archive  Artifact [d31c4758b5]

Artifact d31c4758b5d986dbb005827207bd3ad7f72cc80464d44451a4afab6c0c4ccfdc:

  • File Logoff-all-users.ps1 — part of check-in [e09dc4868e] at 2018-06-10 13:42:54 on branch trunk — This is a little script I wrote to logoff all users on the box except for myself. Clearly it can be cleaned up a little, making it more flexible, but thought I would share anyways. (user: Nigel Stuke size: 985)

# encoding: ascii
# api: powershell
# title: Logoff all users
# description: This is a little script I wrote to logoff all users on the box except for myself. Clearly it can be cleaned up a little, making it more flexible, but thought I would share anyways.
# version: 0.1
# type: function
# author: Nigel Stuke
# license: CC0
# x-poshcode-id: 4549
# x-archived: 2016-03-16T12:51:39
# x-published: 2016-10-24T12:35:00
#
#
function RemoveSpace([string]$text) {  
    $private:array = $text.Split(" ", `
    [StringSplitOptions]::RemoveEmptyEntries)
    [string]::Join(" ", $array) }

$quser = quser
foreach ($sessionString in $quser) {
    $sessionString = RemoveSpace($sessionString)
    $session = $sessionString.split()
    
    if ($session[0].Equals(">nistuke")) {
    continue }
    if ($session[0].Equals("USERNAME")) {
    continue }
    # Use [1] because if the user is disconnected there will be no session ID. 
    $result = logoff $session[1] }