Skip to content

Assert ElevatedUser

dscbot edited this page Sep 30, 2024 · 3 revisions

Assert-ElevatedUser

SYNOPSIS

Assert that the user has elevated the PowerShell session.

SYNTAX

Assert-ElevatedUser [[-ErrorMessage] <String>] [<CommonParameters>]

DESCRIPTION

Assert that the user has elevated the PowerShell session. The command will throw a statement-terminating error if the script is not run from an elevated session.

EXAMPLES

EXAMPLE 1

Assert-ElevatedUser

Throws an exception if the user has not elevated the PowerShell session.

EXAMPLE 2

Assert-ElevatedUser -ErrorMessage 'A custom error message to throw'

Throws an exception if the user has not elevated the PowerShell session.

EXAMPLE 3

`Assert-ElevatedUser -ErrorAction 'Stop'`

This example stops the entire script if it is not run from an elevated PowerShell session.

PARAMETERS

-ErrorMessage

The error message to assign to the exception.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 1
Default value: $script:localizedData.ElevatedUser_UserNotElevated
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

None.

NOTES

RELATED LINKS

Clone this wiki locally