PowerShell因為在此系統(tǒng)中禁止執(zhí)行腳本的解決方法
在Powershell直接腳本時會出現(xiàn):
無法加載文件 ******.ps1,因為在此系統(tǒng)中禁止執(zhí)行腳本。有關詳細信息,請參閱 "get-help about_signing"。
所在位置 行:1 字符: 17
+ E:\Test\test.ps1 <<<<
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
ps1的內容:
在powershell中執(zhí)行 set-ExecutionPolicy RemoteSigned
下圖可以看到原來是無法運行對的,執(zhí)行了上面的命令后就可以了,如下圖
查看“get-help about_signing”:
主題
about_signing
簡短說明
說明如何對腳本進行簽名以使其符合 Windows PowerShell 執(zhí)行策略。
詳細說明
Restricted 執(zhí)行策略不允許任何腳本運行。
AllSigned 和 RemoteSigned 執(zhí)行策略可防止 Windows PowerShell 運行沒有數(shù)字簽名的腳本。
本主題說明如何運行所選未簽名腳本(即使在執(zhí)行策略為 RemoteSigned 的情況下),還說明如何對
腳本進行簽名以便您自己使用。
有關 Windows PowerShell 執(zhí)行策略的詳細信息,請參閱 about_Execution_Policy。
允許運行簽名腳本
-------------------------------
首次在計算機上啟動 Windows PowerShell 時,現(xiàn)用執(zhí)行策略很可能是 Restricted(默認設置)。
Restricted 策略不允許任何腳本運行。
若要了解計算機上的現(xiàn)用執(zhí)行策略,請鍵入:
get-executionpolicy
若要在本地計算機上運行您編寫的未簽名腳本和來自其他用戶的簽名腳本,請使用以下命令將計算機上的
執(zhí)行策略更改為 RemoteSigned:
set-executionpolicy remotesigned
有關詳細信息,請參閱 Set-ExecutionPolicy。
執(zhí)行“set-ExecutionPolicy RemoteSigned
”:
執(zhí)行策略更改
執(zhí)行策略可以防止您執(zhí)行不信任的腳本。更改執(zhí)行策略可能會使您面臨 about_Execution_Policies
幫助主題中所述的安全風險。是否要更改執(zhí)行策略?
[Y] 是(Y) [N] 否(N) [S] 掛起(S) [?] 幫助 (默認值為“Y”): y
Run a CMD batch file
To run a batch script from the CMD shell, save the file as plain ASCII text with the file extension .CMD, then from the command line, enter the name of the script and press return.
C:\Batch> Demo.cmd
To run a batch file from within another batch file, use the CALL command, otherwise the first script will exit without performing any further commands.
It is also possible to run batch scripts with the old (Windows 95 style) .BAT extension, but be aware that these will set ERRORLEVEL differently.
Run a Powershell script
To run a PowerShell script from the CMD shell:
C:\> powershell -file "c:\batch\demo.ps1"
Run a VBScript file
To run a VBScript from the CMD shell:
C:\> cscript c:\batch\demo.vbs
“The method of the enterprising is to plan with audacity and execute with vigor” ~ John Christian Bovee
相關文章
PowerShell重啟服務命令Restart-Service詳細介紹
這篇文章主要介紹了PowerShell重啟服務命令Restart-Service詳細介紹,Restart-Service命令主要用來重啟一些系統(tǒng)級的服務,需要的朋友可以參考下2014-08-08PowerShell腳本實現(xiàn)添加、修改任務計劃的例子
這篇文章主要介紹了PowerShell腳本實現(xiàn)添加、修改任務計劃的例子,PowerShell操作、設置任務計劃實例,需要的朋友可以參考下2014-08-08PowerShell查看本機文件關聯(lián)程序和默認打開程序的方法
這篇文章主要介紹了PowerShell查看本機文件關聯(lián)程序和默認打開程序的方法,本文給出了查看方法,同時給出了一份讀取結果,需要的朋友可以參考下2015-06-06PowerShell實現(xiàn)動態(tài)獲取當前腳本運行時消耗的內存
這篇文章主要介紹了PowerShell實現(xiàn)動態(tài)獲取當前腳本運行時消耗的內存,本文直接給出實現(xiàn)腳本函數(shù),需要的朋友可以參考下2015-06-06PowerShell中使用Out-File把字符串或運行結果保存到文件的方法
這篇文章主要介紹了PowerShell中使用Out-File把字符串或運行結果保存到文件的方法,重點在于Out-File命令的使用方法上,需要的朋友可以參考下2014-08-08Windows Powershell 進行數(shù)學運算
在Windows PowerShell中, 使用數(shù)學運算符來進行數(shù)學運算,數(shù)學運算符允許你在命令參數(shù)中計算數(shù)值. 你可以使用一個或者多個運算符進行加減乘除法, 也可以返回除法的余數(shù)(模). 包含這些計算的參數(shù), 將計算結果作為參數(shù)值. 命令就像處理其他類型參數(shù)一樣, 來處理參數(shù)值.2014-08-08