Skip to main content

Security helpers

Requires a Microsoft Graph session. For full and always-up-to-date details, use Get-Help <FunctionName> -Detailed (or -Examples).

Disable-UserDevices

Disable all registered devices for specified users.

Syntax

Disable-UserDevices -UserPrincipalName <String[]> [-PassThru]
ParameterTypeDescriptionRequiredDefault
UserPrincipalName (Identity)String[]Target users (UPN/object ID/short identifier). Pipeline accepted.Yes-
PassThruSwitchEmit the impacted devices.NoFalse

Example

Disable-UserDevices -UserPrincipalName user1@contoso.com,user2@contoso.com -WhatIf

Disable-UserSignIn

Block sign-in (AccountEnabled = $false) for specified users.

Syntax

Disable-UserSignIn -UserPrincipalName <String[]> [-PassThru]
ParameterTypeDescriptionRequiredDefault
UserPrincipalName (Identity)String[]Target users (UPN/object ID/short identifier). Pipeline accepted.Yes-
PassThruSwitchEmit the impacted users.NoFalse

Example

Disable-UserSignIn -UserPrincipalName user1@contoso.com -Confirm:$false

Revoke-UserSessions

Force sign-out by revoking refresh tokens for users.

Syntax

Revoke-UserSessions [-All] [-UserPrincipalName <String[]>] [-Exclude <String[]>] [-PassThru]
ParameterTypeDescriptionRequiredDefault
AllSwitchTarget every user in the tenant.NoFalse
UserPrincipalName (Identity)String[]Users to target (UPN/object ID/short identifier). Pipeline accepted.No-
ExcludeString[]Users to skip (UPN/object ID/short identifier; applies to both -All and explicit lists).No-
PassThruSwitchEmit the impacted users.NoFalse

Examples

Revoke-UserSessions -UserPrincipalName user1@contoso.com,user2@contoso.com
Revoke-UserSessions -All -Exclude user@contoso.com -Confirm:$false

Notes:

  • Supports -WhatIf/-Confirm for safety.
  • Skips missing users and reports exclusions.
  • User identities are resolved through Find-UserRecipient, so short identifiers are supported.