Block-UserLockUserAccount

Block user accounts from opening new sessions.

Published May 31, 2025

Synopsis

Block user accounts from opening new sessions.

Syntax

powershell
Block-UserLockUserAccount [-UserName] <string[]> [-CreatePermanentPA <bool>] [-Message <string>] [-CloseAllSessions] <bool> [-UserLockServerName <string>] [<CommonParameters>]

Description

The Block-UserLockUserAccount cmdlet blocks one or more user account from opening new sessions by creating of modifying the user protected accounts. Caution: PowerShell 3.0 is required.

Parameters

-UserName <string[]>

Specifies one or more user account names. You can type multiple account names (separated by commas). Wildcard characters are managed only if the concerned user accounts did make at least one session event in UserLock (if they are displayed in the User sessions view).

Required

true

Position

1

Accepts pipeline input

true (ByValue, ByPropertyName)

Accepts wildcard characters

false

-CreatePermanentPA <bool>

True to create a new permanent protected account related to the same user (only if there is no other existing permanent).

Required

false

Position

named

Accepts pipeline input

false

Accepts wildcard characters

false

Default Value

true

-Message <string>

Message to display when a blocked user opens a session.

Required

false

Position

named

Accepts pipeline input

false

Accepts wildcard characters

false

-CloseAllSessions <bool>

True if all the opened sessions has to be closed after blocking, otherwise false. Note that it is impossible to block a user leaving existing sessions open if the "LogoffExceedingSessions" server property is enabled. If so, existing sessions will be closed (as if the "CloseAllSessions" switch parameter was set to true).

Required

true

Position

named

Accepts pipeline input

false

Accepts wildcard characters

false

Default Value

false

-UserLockServerName <string>

Specifies the name of the UserLock server. The default is the localhost name.

Required

false

Position

named

Accepts pipeline input

false

Accepts wildcard characters

false

Default Value

'.'

<CommonParameters>

For more information about common parameters, type "Get-Help about_commonparameters".

Input Type

None

Return Type

System.String[]

Notes

You can also refer to Block-UserLockUserAccount by its alias, "bulua". For more information, see about_Aliases. To use Block-UserLockUserAccount, you must have the "Protected account" UserLock administrative access rights.

Examples

Example 1

powershell
Block-UserLockUserAccount -UserName 'Alice', 'Bob' -UserLockServerName 'MyUlSrv'

Blocks the 'Alice' and 'Bob' users from opening new sessions through the 'MyUlSrv' UserLock server, the command will create new permanent protected accounts related to the users (only if there is no other existing permanents).

Example 2

powershell
Block-UserLockUserAccount -UserName 'Alice' -Message 'You have been blocked' -CloseAllSessions $true

Blocks the 'Alice' user from opening new sessions through the localhost UserLock server, and close all session already opened. The configured message will be showed to the user trying to open a session.

Unblock-UserLockUserAccount