PoshCode Archive  Artifact [e0031e5050]

Artifact e0031e50508323c77a2b7520319da60e6fefebf7a0d89460d042667574a9f272:

  • File Logoff-all-users.ps1 — part of check-in [fa3c1abee5] at 2018-06-10 13:29:24 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: roger size: 979)

# 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: roger
# license: CC0
# x-poshcode-id: 3685
# x-archived: 2012-11-19T05:03:00
# x-published: 2012-10-10T08:54: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] }