Powershell modules and admin privileges -


i have written powershell module contains cmdlets utilize iis's webadministration powershell module. however, module requires loaded admin powershell session, otherwise exception thrown. might know or guess, custom module fails load when powershell not first run admin.

this behavior acceptable , expected. question whether or not there way elevate shell's permissions (and obey uac settings) when module loaded?

example: (assume in particular case, import-module webadministration found in powershell profile)

  1. i click powershell shortcut on task bar.
  2. a powershell shell standard user permissions opens, , attempts import module.
  3. encounters fact module needs elevated permissions.
  4. user prompted , powershell restarts.

my question whether or not there way elevate shell's permissions when module loaded?

no; security hole. can write this:

#requires -runasadministrator 

(iirc, -runasadministrator first appeared in powershell 3.0, if need ps 2.0 compatibility, need approach things differently.)

see help about_requires more information.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -