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)
- i click powershell shortcut on task bar.
- a powershell shell standard user permissions opens, , attempts import module.
- encounters fact module needs elevated permissions.
- 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
Post a Comment