Enable Privilege
Enable Privilege
Enable Privilege
<#
.SYNOPSIS
Enables specific privilege or privileges on the current process.
.DESCRIPTION
Enables specific privilege or privileges on the current process.
.PARAMETER Privilege
Specific privilege/s to enable on the current process
.NOTES
Name: Enable-Privilege
Author: Boe Prox
Version History:
1.0 - Initial Version
.EXAMPLE
Enable-Privilege -Privilege SeBackupPrivilege
Description
-----------
Enables the SeBackupPrivilege on the existing process
.EXAMPLE
Enable-Privilege -Privilege SeBackupPrivilege, SeRestorePrivilege, SeTakeOwnershipPrivilege
Description
-----------
Enables the SeBackupPrivilege, SeRestorePrivilege and SeTakeOwnershipPrivilege on the existin
#>
[cmdletbinding(
SupportsShouldProcess = $True
)]
Param (
[parameter(Mandatory = $True)]
[Privileges[]]$Privilege
)
If ($PSCmdlet.ShouldProcess("Process ID: $PID", "Enable Privilege(s): $($Privilege -join ', ')")) {
#region Constants
$SE_PRIVILEGE_ENABLED = 0x00000002
$SE_PRIVILEGE_DISABLED = 0x00000000
$TOKEN_QUERY = 0x00000008
$TOKEN_ADJUST_PRIVILEGES = 0x00000020
#endregion Constants
$TokenPriv = New-Object TokPriv1Luid
$HandleToken = [intptr]::Zero
$TokenPriv.Count = 1
$TokenPriv.Attr = $SE_PRIVILEGE_ENABLED