如果你知道执行你的脚本需要管理员权限,这时你最好追加一行在你的脚本顶部:
#requires -runasadministrator
这行将让你明白这个脚本只可以在管理员权限下运行。告诉用户无论你怎么操作,不提升脚本的权限的话 脚本甚至不能开始或会在中间失败。
原文地址:Blocking Administrator Scripts
本文链接: https://www.pstips.net/blocking-administrator-scripts.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
这个需要Powershell 4.0 才支持的帮助 helo about_Requires
低版本的ps,可以使用《强制PowerShell脚本以管理员权限运行》:http://www.pstips.net/force-script-run-as-admin.html
3.0 开始支持的吧这个玩意儿好!不用自己再写探测语句,简单粗暴!
不好意思!”-runasadministrator” 是 4.0 才有。#Requires 是 3.0 的功能