微軟正式釋出PowerShell Core 6.0
在2018年初,微軟終於正式釋出了PowerShell Core 6.0。可以說PowerShell Core 6.0是全新的PowerShell版本,用官方的話來說它不同以往因為它是建立在跨平臺(支援Windows, macOS, Linux),開源並且為異構環境和混合雲而生。
我相信不少人肯定會有點分不清最早我們用的PowerShell和這個PowerShell Core 6.0有什麼區別,是不是所謂的6.0就是之前PowerShell的新版本,其實還真是有區別的,兩者不一樣。以前我們在Windows用的PowerShell,我們稱為Windows PowerShell,而今天說的這個是PowerShell Core 6.0(沒錯,一發行,微軟就給它搞了一個6.0命名而不是Core 1.0)。其實也意味著 PowerShell 現在已經分了兩大版本系列,基於.NET Framework的Windows PowerShell和基於.NET Core的 PowerShell Core,就微軟目前的動向來看,這兩個版本將會並行工作。
那Windows PowerShell與PowerShell Core 6.0又有什麼區別呢,主要幾個區別如下:
- 顧名思義,Windows PowerShell是基於.NET Framework的,所以它也只能在Windows中使用。
- PowerShell Core 6.0釋出時,Windows PowerShell 最新的版本在5.*,但PowerShell Core 6.0 可不是Windows PowerShell的升級版本。
- PowerShell Core 6.0因為它的跨平臺,自然不僅可以在 Windows 上執行也可以在其它平臺如macOS與Linux上執行,因為它是基於.NET Core基礎之上的。
- Windows PowerShell在 Windows 中的執行檔案為powershell.exe,而PowerShell Core 6.0在Windows中的執行檔案是pwsh.exe,在 macOS 和 Linux 中的執行檔案是 pwsh
那PowerShell Core可以執行Windows PowerShell裡的cmdlet命令嗎?
目前看來並非所有命令都可以無縫相容兩個平臺,諸如Windows PowerShell基於WMF自帶的那些模組命令,甚至微軟服務產品系列的模組是肯定不會做到相容的,畢竟它們目前無法很好的在macOS、Linux上使用。不過只要沒有明確說明不可以在PowerShell Core上用的話,通過一個方法還是有可能在PowerShell Core 6.0裡使用的。官方在這方面給出了一個方法,就是通過安裝WindowsPSModulePath
# 安裝WindowsPSModulePath模組
Install-Module WindowsPSModulePath -Force
# 把Windows PowerShell PSModulePath 新增到 PowerShell Core
Add-WindowsPSModulePath
PowerShell Core支援在以下平臺執行:
- Windows 7、8.1 和 10
- Windows Server 2008 R2、2012 R2、2016
- Windows Server 半年頻道
- Ubuntu 14.04、16.04 和 17.04
- Debian 8.7+ 和 9
- CentOS 7
- Red Hat Enterprise Linux 7
- OpenSUSE 42.2
- Fedora 25、26
- macOS 10.12+
而且微軟也公開說明了PowerShell Core 的版本 6.x 分支(例如 6.0、6.1、6.2 等)大約會每六個月更新一次。可見微軟對於PowerShell Core的更新和投入的精力是十分大的。