PoshCode Archive  Artifact [ea3a17c07d]

Artifact ea3a17c07d8da9ba730af7f25ae59c6ca2adab591a9372b8e18fdaf44b71f532:

  • File Force-current-user-logof.ps1 — part of check-in [f41e75143b] at 2018-06-10 13:56:18 on branch trunk — A simple function to force current user logoff without warning. The function takes one computer name or a list of computer names. (user: lieuhon size: 989)

# encoding: ascii
# api: powershell
# title: Force current user logof
# description: A simple function to force current user logoff without warning.  The function takes one computer name or a list of computer names.
# version: 0.1
# type: function
# author: lieuhon
# license: CC0
# function: exit-CurrentUser
# x-poshcode-id: 5503
# x-archived: 2015-01-31T20:28:51
# x-published: 2015-10-10T01:37:00
#
# It works on Windows 7 systems in a Active Directory domain.
#
function exit-CurrentUser
{
  <#
    .SYNOPSIS
        Force current logon user logoff; be careful, there is no warning will be given to user!!

    .EXAMPLE
        Exit-CurrentUser -computer com1
  #>
    param (
        [parameter(
            Mandatory = $true,
            ValueFromPipeline=$true)]
        [string[]]
        $computers
    )
    foreach ($computer in $computers) {
        [Void](gwmi -Class Win32_OperatingSystem -ComputerName $computer).Win32Shutdown(4)
    }
}