PoshCode Archive  Artifact [fc6ab876ba]

Artifact fc6ab876ba876ff4c3b0735913da37a8f6bc6b37e17744087fd52264db707f15:

  • File Logoff.ps1 — part of check-in [c95822c9ad] at 2018-06-10 14:14:23 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: 975)

# encoding: ascii
# api: powershell
# title: Logoff
# 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: 6374
# x-archived: 2016-06-16T09:35:11
# x-published: 2016-06-08T17:04: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] }