Functions/Invoke-UserLogoff.ps1
function Invoke-UserLogoff { [CmdletBinding()] param ( [Parameter()] [string] $UserName, [Parameter()] [string] $Identity, [Parameter()] [string] [ValidateSet("Active", "Disc")] $State, [Parameter()] [int] $IdleTimeHours, [Parameter()] [int] $IdleTimeMinutes ) $PSBoundParameters.GetEnumerator() | ForEach-Object { # "$($_.Key): $($_.Value)" $ParamSet = $true $ParamSet | Out-Null } # $PSBoundParameters.GetEnumerator().Key if (!($ParamSet)) { Write-Warning "No parameters supplied" break } $Param = @{} if ($State) { $param.Add("State", $State) } if ($Identity) { $param.Add("Identity", $Identity) } if ($UserName) { $param.Add("UserName", $UserName) } if ($IdleTimeHours) { $param.Add("IdleTimeHours", $IdleTimeHours) } if ($IdleTimeMinutes) { $param.Add("IdleTimeMinutes", $IdleTimeMinutes) } $Sessions = Get-Quser @Param $Sessions | ForEach-Object { Write-Verbose "Logoff user $($_.UserName) ($($_.ID))..." logoff.exe $_.ID } } |