2013-03-05 30 views
0

我創建了PowerShell腳本來從子文件夾獲取文件。這時候執行我後手動輸入Set-ExecutionPolicy unrestricted從PowerShell控制檯運行,但是當我打電話相同的腳本從批處理文件在從批處理文件調用powershell腳本時執行策略錯誤,powershell v 1.0

C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe D:\programs\abc\bin\xyz_clean.ps1 

它拋出一個錯誤:

xyz_clean.ps1 cannot be loaded because the execution of scripts is disabled on this system.

+0

你在運行什麼操作系統(包括32位和64位)? – alroc 2013-03-05 15:20:45

+4

您是否試過在批處理中指定執行策略? 'C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ PowerShell.exe -executionpolicy unrestricted -file D:\ programs \ abc \ bin \ xyz_clean.ps1' 除此之外,您的「每位用戶「和」機器「執行策略,你可以嘗試使用你缺少-file選項的set-executionpolicy – Poorkenny 2013-03-05 15:22:57

+0

的'-scope'參數。 PowerShell腳本是否被組策略拒絕? – 2013-03-05 15:23:58

回答

2

您只需撥打PowerShell與一個命令行窗口:

C:\> powershell /? 
C:\> powershell -executionpolicy unrestricted -file \\server\file.ps1 

然後將其保存到一個.bat文件:

C:\> echo powershell -executionpolicy unrestricted -file \\server\file.ps1 > file.bat 
相關問題