如何解决特定脚本的Set-ExecutionPolicy
是否可以在全球范围内 override func viewDidLoad() {
super.viewDidLoad()
statTable.dataSource = self
statTable.delegate = self
getStats()
}
func getStats() {
if let currentUser = Auth.auth().currentUser?.uid {
firestoreDB
.collection("stats")
.document(currentUser)
.addSnapshotListener { (documentSnapshot,error) in
if error != nil {
print(error!.localizedDescription)
}
else {
if let document = documentSnapshot {
tableData = document
}
}
self.statTable.reloadData()
}
}
}
func filterData(filter) {
}
使用特定脚本?我知道可以打开Set-ExecutionPolicy
并为特定脚本设置策略,如下所示:
PowerShell
但是我试图全局设置该脚本的策略,因此无论我如何打开powershell.exe -ExecutionPolicy Bypass -File C:\Script\From\Internet.ps1
,它都会为该文件设置该策略。这样,如果我从“开始”菜单中打开PowerShell
,或者如果VS Code打开了PowerShell
终端,则该脚本将始终有效/运行。
PowerShell
没有Set-ExecutionPolicy
的参数,因此我不确定如何为特定文件全局设置它。
解决方法
否。
如所记录的,没有在脚本级别设置EP的概念。
您必须按照已经显示的那样做...
powershell.exe -ExecutionPolicy Bypass -File C:\Script\From\Internet.ps1
......顺便说一句,它不在脚本级别(因为没有此类内容),因此您是默认进程级别。
您可以将EP(EP)添加到您的个人资料中...
- Microsoft.PowerShell_profile.ps1
- Microsoft.PowerShellISE_profile.ps1
- Microsoft.VSCode_profile.ps1
...,但这适用于您启动的任何PowerShell实例。
Again,as documented,there are only 5 options (file/script is not one of them):
- MachinePolicy
- UserPolicy
- 过程
- CurrentUser
- LocalMachine
您要接近的唯一选择是使用已经显示的命令在桌面上创建自定义快捷方式,并将其固定在所需的位置。
更改EP的唯一真正原因是,如果Machine EP通过GPO实施的限制更严格(Restricted或AllSigned),则您需要在此范围之外进行工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。