当前位置:   article > 正文

CMD命令行修改.ps1文件(powershell脚本)的默认打开方式_ps1文件怎么打开

ps1文件怎么打开

只需要以管理员身份运行CMD命令行,执行一次以下代码,以后即可双击运行 .ps1 脚本:

ftype Microsoft.PowerShellScript.1="%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" "%1"
  • 1

恢复方法:

ftype Microsoft.PowerShellScript.1="%SystemRoot%\system32\notepad.exe" "%1"
  • 1

若双击出现PowerShell窗口闪退的情况,可能是没有打开Powershell脚本执行的组策略权限,关于Powershell组策略权限的详细解释见Microsoft官方对于PowerShell执行策略的说明,若页面访问出错或找不到页面,尝试在Powershell中运行已编写好的脚本,会给出参阅链接,如下图所示。
在这里插入图片描述
一般情况使用如下命令在powershell命令行中设置当前用户的remote权限即可

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
  • 1

若要关闭权限,重新设置为Undefined即可

Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser
  • 1
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
  

闽ICP备14008679号