2013-05-01 335 views
0

如何讓我的PowerShell腳本執行?無法執行PowerShell腳本

當我運行我的腳本,我得到的錯誤:
File cannot be loaded because the execution of scripts is disabled on this system

你能幫我把我的腳本來運行?

set-executionpolicy unrestricted 
#Set-ExecutionPolicy RemoteSigned 

$target=[IO.File]::ReadAllText(".\usermenuTest1.4d") 
$output=[IO.File]::ReadAllText(".\usermenuTest2.4d") 

($output -replace $target) | Set-Content "usermenuTest2.4d.new" 

Start-Sleep -s 10 

回答

3

This Technet article建議嘗試Get-ExecutionPolicy檢查你的腳本執行的政策,然後將其設置爲AllSignedUnrestricted。另外,確保你運行這樣的腳本".\scriptname.ps1"

+0

RemoteSigned是ExecutionPolicy的另一個廣泛使用的值。 – 2013-05-01 03:45:36

+5

'&powershell.exe -executionpolicy bypass -file C:\ script.ps1'完全忽略執行策略。 – 2013-05-01 04:46:07

+0

您也可以使用Set-ExecutionPolicy Unrestricted -Scope Process -Force暫時解決它而不更改系統默認值 – 2013-05-01 12:06:04