# encoding: ascii
# api: powershell
# title: Set-Privilege
# description: I thought that it’s impossible. Some guy who calls himself gregzakh wrote a demo module called Func which allows you to invoke some WinAPI functions without defining dynamic modules in memory. This module correctly works on PowerShell v2, 4 and 5 (I have not got PowerShell v3 to test it). The script below uses Func library to set SeShutwondPrivilege privilege up for current PowerShell host.
# version: 0.1
# type: script
# author: Dan Jones
# license: CC0
# function: Set-Privilege
# x-poshcode-id: 6358
# x-archived: 2016-05-28T02:16:52
# x-published: 2016-05-25T07:33:00
#
#
# this script is a part of Func module (https://github.com/gregzakh/Func)
function Set-Privilege {
  param(
    [Parameter(Position=0)]
    [ValidateRange(2, 35)]
    [UInt32]$Privilege = 19, #SeShutdownPrivilege
    
    [Parameter(Position=1)]
    [Switch]$Enable = $true
  )
  
  begin {
    $ptr, $null = Get-ProcAddress ntdll RtlAdjustPrivilege
    $RtlAdjustPrivilege = Set-Delegate $ptr `
         '[Action[UInt32, Boolean, Boolean, Text.StringBuilder]]'
    $ret = New-Object Text.StringBuilder
  }
  process {
    $RtlAdjustPrivilege.Invoke($Privilege, $Enable, $false, $ret)
  }
  end {}
}
