PoshCode Archive  Artifact [54d4af9131]

Artifact 54d4af9131933c34d97666e106c432c1427a6156bbb98faf7127df9675c8631a:

  • File Logoff-all-users.ps1 — part of check-in [79156ce49c] at 2018-06-10 13:53:16 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: testing size: 981)

# 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: testing
# license: CC0
# x-poshcode-id: 5313
# x-archived: 2015-01-31T20:32:11
# x-published: 2015-07-17T01:44: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] }