如何解决PowerShell的ps1脚本执行异常提示?

cmd shell

1 前言

一个问题,一篇文章,一出故事。
笔者最近需创建一个测试的PowerShell脚本,后缀名称ps1,执行发现有如下错误提示,

File D:\test.ps1 cannot be loaded 
because running scripts is disabled on this system. For more information, see about_Execution_Policies at 
https:/go.microsoft.com/fwlink/?LinkID=135170.
    + CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnauthorizedAccess

为解决以上问题,于是整理此文。

2 最佳实践

2.1 运行PowerShell

按下【Win+R】键,然后执行以下命令,

powershell

2.2 切换到管理模式

Start-Process powershell -Verb runAs

2.3 执行策略切换到非注册模式

Set-ExecutionPolicy unrestricted
没有评论

发表回复

Windows
如何修改Windows的时区?

1 前言 一个问题,一篇文章,一出故事。 笔者由于需要使用命令设置Windows系统的时区,于是整理 …

Windows
如何熟悉微软的OAuth 2.0和OpenID Connect?

1 OAuth的基础知识 1.1 OAuth的简介 – OAuth即Open Autho …

cmd shell
如何bat免密码登录Windows?

1 前言 一个问题,一篇文章,一出故事。 笔者最近想通过bat自动登录Windows服务器,于是整理 …