解決“系統上已停用指令碼執執行“錯誤
首先要先允許使用自定指令碼。
來源1
當我們使用 PowerShell 執行自定 script 檔,卻出現「檔案無法載入,因為這個系統已停用指令碼執行」的訊息,表示在目前作業系統中的執行原則 (Excution Policy) 預設狀態為 Restricted,也就是不允許執行。
可用管理員權限打開 PowerShell,執行以下指令:5
1
Set-ExecutionPolicy RemoteSigned
Oh-my-posh
官方
特色
- 安裝簡易
- 快速選擇的命令
- Git 狀態指示(由 posh-git 提供支持)
- 提示失效的命令
- 提示管理員
- 提示當前會話(admin,failed command ,user)
- 自設定
- 輕鬆創建自己的主題
- 單獨設置 oh-my-posh 和 posh-git
要完整使用 oh my posh ,需要使用第三方 console 來加載有 Powerline 補釘的字體,個人是使用 Cmder。
安裝 oh-my-posh
用管理員權限開啟 Powershell 輸入以下指令安裝 posh-git 和 oh-my-posh:
12
Install-Module posh-git -Scope CurrentUserInstall-Module oh-my-posh -Scope CurrentUser
這時就可以用 set-theme 再按 tab 選要使用的 theme。
用以下指令開啟或建立個人 Powershell 設定檔
12
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }notepad $PROFILE
自動啟用
加入以下內容到個人設定檔,讓開啟時自動載入
123
Import-Module posh-gitImport-Module oh-my-poshSet-Theme paradox
Cmder 設定
Main:Main console font 選有打過 Powerline 的字體,可在 這裡 下載
PowerShell 顯示資料夾時上色
這個功能個人覺得很好用,一並記錄一下。
安裝:先轉移到個人模組位置
1
cd $ENV:UserProfile\Documents\WindowsPowerShell\Modules
從 GitHub 安裝
1
git clone https://github.com/joonro/Get-ChildItemColor.git
使用(也可將其寫入個人設定檔中)
123Import-Module Get-ChildItemColoSet-Alias l Get-ChildItemColor -option AllScopeSet-Alias ls Get-ChildItemColorFormatWide -option AllScope