PoshCode Archive  Artifact [db0a71d035]

Artifact db0a71d035bd26645b0cf1e6fb8ebf6ccd6e5ceabc4b6e8830dfb4881657e263:

  • File Logoff-all-users.ps1 — part of check-in [7ff0fcca73] at 2018-06-10 13:29:28 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: 3688
# x-archived: 2016-03-17T12:30:17
# x-published: 2013-10-12T05:53: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] }