只需要以管理员身份运行CMD命令行,执行一次以下代码,以后即可双击运行 .ps1 脚本:
ftype Microsoft.PowerShellScript.1="%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" "%1"
恢复方法:
ftype Microsoft.PowerShellScript.1="%SystemRoot%\system32\notepad.exe" "%1"
若双击出现PowerShell窗口闪退的情况,可能是没有打开Powershell脚本执行的组策略权限,关于Powershell组策略权限的详细解释见Microsoft官方对于PowerShell执行策略的说明,若页面访问出错或找不到页面,尝试在Powershell中运行已编写好的脚本,会给出参阅链接,如下图所示。

一般情况使用如下命令在powershell命令行中设置当前用户的remote权限即可
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
若要关闭权限,重新设置为Undefined即可
Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser
本文介绍如何配置Windows系统以便直接双击运行.ps1 PowerShell脚本文件,并提供了恢复默认设置的方法。此外还介绍了如何通过调整组策略权限来解决PowerShell窗口闪退的问题。
572





