微软正式发布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模块来把Windows PowerShell中PSModulePath添加到PowerShell Core中的PSModulePath,这样就可以使用那些兼容性的命令了,具体参见如下:

# 安装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的更新和投入的精力是十分大的。
微软正式发布PowerShell Core 6.0_第1张图片

后续我也会跟进继续写一些PowerShell Core相关的文章,其实有关于PowerShell Core 6.0的新特性和更新还有很多,比如支持Docker、SSH Remoting、性能提高等等,具体可以查看官方网站:
https://docs.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-core-60?view=powershell-6

你可能感兴趣的:(PowerShell)