• Powershell执行策略限制相关


    1.git status

    报错:
    git : 无法将“git”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,
    然后再试一次。

    解决方法:

    Windows给powershell设定了一个叫“执行策略”的东西。

    为什么要弄这么一个执行策略呢,因为powershell能做的事情太多了,为了避免一些恶意脚本直接运行,一般家用的windows系统默认将执行策略设置成了“Restricted”,即受限制的。

    我们可以运行命令来查看自己电脑上的执行策略被设置成了什么:

    cmd Get-ExecutionPolicy -LIST

    显示:

    Scope ExecutionPolicy
    ----- ---------------
    MachinePolicy Undefined
    UserPolicy Undefined
    Process Undefined
    CurrentUser Undefined
    LocalMachine Unrestricted

    或者运行Get-ExecutionPolicy,输出Restricted

    说明电脑是受限制的,不能运行任何的脚本。

    所有的执行策略如下所示(参考About Execution Policies):

    AllSigned. 要求所有脚本和配置文件均需受信任的发布者签名,包括在本地计算机上编写的脚本。(安全但是本地编写的脚本也要签名,麻烦)
    Bypass. 不会阻止你运行任何脚本,也没有提示和警告。(不安全)
    Default. 默认的执行策略,普通桌面Windows默认Restricted,服务器windows默认RemoteSigned。
    RemoteSigned. 要求从互联网上下载的所有脚本和配置文件均需要受信任的发布者签名,本地脚本则不需要签名。是Windows服务器的默认执行策略。(较为安全)
    Restricted. 无法加载配置文件或运行脚本。桌面Windows的默认执行策略。(安全,但无法运行脚本)
    Undefined. No execution policy is set for the scope. Removes an assigned execution policy from a scope that is not set by a Group Policy. If the execution policy in all scopes is Undefined, the effective execution policy is Restricted.(这里的Undefined不知道是什么东西,先不管它)
    Unrestricted. 从PowerShell 6.0开始,这是非Windows系统的默认执行策略,并且不能更改。 能够加载任何配置文件和运行任何脚本。如果运行从网上下载的未签名脚本,则会在运行之前提示您获得许可。(不安全)
    经过权衡安全和便捷,决定设置成RemoteSigned策略,运行一下命令

    cmd执行Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

    设置当前用户作用域具备权限,具体设置格式是这样的:Set-ExecutionPolicy -ExecutionPolicy <PolicyName> -Scope <scope>

    执行策略更改

    显示:
    执行策略可帮助你防止执行不信任的脚本。更改执行策略可能会产生安全风险,如 https:/go.microsoft.com/fwlink/?LinkID=135170
    中的 about_Execution_Policies 帮助主题所述。是否要更改执行策略?
    [Y] 是(Y) [A] 全是(A) [N] 否(N) [L] 全否(L) [S] 暂停(S) [?] 帮助 (默认值为“N”): y
    Set-ExecutionPolicy : 对注册表项“HKEY_LOCAL_MACHINESOFTWAREMicrosoftPowerShell1ShellIdsMicrosoft.PowerShell”的
    访问被拒绝。 要更改默认(LocalMachine)作用域的执行策略,请使用“以管理员身份运行”选项启动 Windows PowerShell。要更改当
    前用户的执行策略,请运行 "Set-ExecutionPolicy -Scope CurrentUser"。
    所在位置 行:1 字符: 1
    + Set-ExecutionPolicy Unrestricted
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : PermissionDenied: (:) [Set-ExecutionPolicy], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand

    用户如果是第一次使用powershell 执行脚本 的话。其中的原因是:

    windows默认不允许任何脚本运行,你可以使用"Set-ExecutionPolicy"cmdlet来改变的你PowerShell环境。

    你可以使用如下命令让PowerShell运行在无限制的环境之下:

    Set-ExecutionPolicy Unrestricted

    Unrestricted 为允许所有的脚本运行

    在win7(含)以上必须使用管理员的权限启动命令命令行,否则会报“Set-ExecutionPolicy : 对注册表项“HKEY_LOCAL_MACHINESOFTWAREMicrosoftPowerShell1ShellIdsMicrosoft.PowerShell”的访问被拒绝。”错误。

  • 相关阅读:
    PHP加速器eAccelerator安装
    WCF
    WCF
    WCF
    前端学习书籍推荐
    问题集录01--java对list列表进行排序
    基础知识:字符编码
    基础知识:if条件、while循环、for循环 相关练习
    基础知识:语言、编程、计算机组成、cpu、存储器
    视图 索引 存储过程
  • 原文地址:https://www.cnblogs.com/luckyuns/p/12851317.html
Copyright © 2020-2023  润新知