剛開始使用powershell,導入管理子產品或者其他操作的時候會出現因為在此系統中禁止執行腳本的報錯,報錯内容如下:
windows powershell
版權所有 (c) 2009 microsoft corporation。保留所有權利。
ps c:windowssystem32> d:workshoppowershellsprinklersrcscriptssprinkle.ps1
無法加載檔案 d:workshoppowershellsprinklersrcscriptssprinkle.ps1,因為在此系統中禁止執行腳本。有關詳細資訊,請參
閱 "get-help about_signing"。
所在位置 行:1 字元: 58
d:workshoppowershellsprinklersrcscriptssprinkle.ps1 <<<<
categoryinfo : notspecified: (:) [], pssecurityexception
fullyqualifiederrorid : runtimeexception
ps c:windowssystem32> get-executionpolicy
restricted
果然,是被限制。還是在"get-help about_signing"裡面可以查到設定指令"set-executionpolicy"
再在幫助中找到"set-executionpolicy"的說明。。似乎是比較建議設定為,至少是被标記為可信任的
-- remotesigned: requires that all scripts and configuration files downloaded from the internet be signed by a trusted publisher.
在powershell執行以下:
ps c:windowssystem32> set-executionpolicy remotesigned
執行政策更改
執行政策可以防止您執行不信任的腳本。更改執行政策可能會使您面臨 about_execution_policies
幫助主題中所述的安全風險。是否要更改執行政策?
[y] 是(y) [n] 否(n) [s] 挂起(s) [?] 幫助 (預設值為“y”): y
ps c:windowssystem32>
本文來自雲栖社群合作夥伴“donet跨平台”,了解相關資訊可以關注“opendotnet”微信公衆号