Power Shell Core 6.0をCentOS7で使ってみる


2017/02/01にPowerShell Core 6.0がLinux環境向けにもリリースされた
Installing latest PowerShell Core 6.0 Release on Linux just got easier!

PowerShellの開発はGithubの「https://github.com/PowerShell/PowerShell」で行われており、導入手順も書かれている。
github上の「Linux向けインストール手順」では、直接RPMファイル/debファイルを指定してインストールする、というものが記載されている。

しかし、「Installing latest PowerShell Core 6.0 Release on Linux just got easier!」の記事の中では、yumやaptなどでプログラムの更新をサポートする形でのインストール手順が示されている。

CentOS7だと下記のようになる

# curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/microsoft.repo
# yum install powershell
#

実際に実行してみると下記の様になります。

[root@blog ~]# curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/microsoft.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   193  100   193    0     0    209      0 --:--:-- --:--:-- --:--:--   210
[root@blog ~]# yum install powershell
読み込んだプラグイン:fastestmirror, langpacks
packages-microsoft-com-prod                              | 2.9 kB     00:00
packages-microsoft-com-prod/primary_db                     | 9.9 kB   00:00
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.riken.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ powershell.x86_64 0:6.0.0_alpha.15-1.el7.centos を インストール
--> 依存性の処理をしています: uuid のパッケージ: powershell-6.0.0_alpha.15-1.el7.centos.x86_64
--> 依存性の処理をしています: libicu のパッケージ: powershell-6.0.0_alpha.15-1.el7.centos.x86_64
--> 依存性の処理をしています: libunwind のパッケージ: powershell-6.0.0_alpha.15-1.el7.centos.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ libicu.x86_64 0:50.1.2-15.el7 を インストール
---> パッケージ libunwind.x86_64 2:1.1-5.el7_2.2 を インストール
---> パッケージ uuid.x86_64 0:1.6.2-26.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

================================================================================
 Package   アーキテクチャー
                  バージョン                  リポジトリー                 容量
================================================================================
インストール中:
 powershell
           x86_64 6.0.0_alpha.15-1.el7.centos packages-microsoft-com-prod  39 M
依存性関連でのインストールをします:
 libicu    x86_64 50.1.2-15.el7               base                        6.9 M
 libunwind x86_64 2:1.1-5.el7_2.2             base                         56 k
 uuid      x86_64 1.6.2-26.el7                base                         55 k

トランザクションの要約
================================================================================
インストール  1 パッケージ (+3 個の依存関係のパッケージ)

総ダウンロード容量: 46 M
インストール容量: 64 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): uuid-1.6.2-26.el7.x86_64.rpm                        |  55 kB   00:00
(2/4): libunwind-1.1-5.el7_2.2.x86_64.rpm                  |  56 kB   00:00
(3/4): libicu-50.1.2-15.el7.x86_64.rpm                     | 6.9 MB   00:04
warning: /var/cache/yum/x86_64/7/packages-microsoft-com-prod/packages/powershell-6.0.0_alpha.15-1.el7.centos.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID be1229cf: NOKEY
powershell-6.0.0_alpha.15-1.el7.centos.x86_64.rpm の公開鍵がインストールされていません
(4/4): powershell-6.0.0_alpha.15-1.el7.centos.x86_64.rpm   |  39 MB   00:21
--------------------------------------------------------------------------------
合計                                               2.2 MB/s |  46 MB  00:21
https://packages.microsoft.com/keys/microsoft.asc から鍵を取得中です。
Importing GPG key 0xBE1229CF:
 Userid     : "Microsoft (Release signing) <gpgsecurity@microsoft.com>"
 Fingerprint: bc52 8686 b50d 79e3 39d3 721c eb3e 94ad be12 29cf
 From       : https://packages.microsoft.com/keys/microsoft.asc
上記の処理を行います。よろしいでしょうか? [y/N]y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : uuid-1.6.2-26.el7.x86_64                        1/4
  インストール中          : 2:libunwind-1.1-5.el7_2.2.x86_64                2/4
  インストール中          : libicu-50.1.2-15.el7.x86_64                     3/4
  インストール中          : powershell-6.0.0_alpha.15-1.el7.centos.x86_64   4/4
  検証中                  : powershell-6.0.0_alpha.15-1.el7.centos.x86_64   1/4
  検証中                  : libicu-50.1.2-15.el7.x86_64                     2/4
  検証中                  : 2:libunwind-1.1-5.el7_2.2.x86_64                3/4
  検証中                  : uuid-1.6.2-26.el7.x86_64                        4/4

インストール:
  powershell.x86_64 0:6.0.0_alpha.15-1.el7.centos

依存性関連をインストールしました:
  libicu.x86_64 0:50.1.2-15.el7         libunwind.x86_64 2:1.1-5.el7_2.2
  uuid.x86_64 0:1.6.2-26.el7

完了しました!
[root@blog ~]#

が・・・
私の環境では、いつもの癖で「ls」と実行してしまったら・・・

bash-4.2$ ls
11-0-1-0048_SAS_FW_Image_1-40-342-1650.zip  MegaSAS.log  sql  web  work
bash-4.2$ powershell
PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS /home/osakanataro> ls
11-0-1-0048_SAS_FW_Image_1-40-342-1650.zip  MegaSAS.log  sql  web  work
(ここで応答が無くなる)

ん???
UNIX系コマンドをPowerShellから実行した場合の動作に難有りなのかも?

PS /home/osakanataro> Get-Item *| ForEach-Object { $_ }


    Directory: /home/osakanataro


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-r---       2017/02/06     17:35                sql
d-----       2017/02/03     19:08                web
d-----       2017/02/03     19:19                work
------       2017/01/04     13:01        1528036 11-0-1-0048_SAS_FW_Image_1-40-
                                                 342-1650.zip
--r---       2017/01/04     13:07            390 MegaSAS.log

PS /home/osakanataro> dir


    Directory: /home/osakanataro


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-r---       2017/02/06     17:35                sql
d-----       2017/02/03     19:08                web
d-----       2017/02/03     19:19                work
------       2017/01/04     13:01        1528036 11-0-1-0048_SAS_FW_Image_1-40-
                                                 342-1650.zip
--r---       2017/01/04     13:07            390 MegaSAS.log


PS /home/osakanataro>

PwerShellらしいこと、ということで、下記の処理をやってみる

PS /home/osakanataro> $results=Get-Item *| ForEach-Object { $_ }
PS /home/osakanataro> $results | Export-Csv test.csv -Encoding UTF  (タブ補完で候補を出す)
UTF32  UTF7   UTF8
PS /home/osakanataro> $results | Export-Csv test.csv -Encoding UTF8 -No  (タブ補完で候補を出す)
NoClobber          NoOverwrite        NoTypeInformation
PS /home/osakanataro> $results | Export-Csv test.csv -Encoding UTF8 -NoTypeInformation
PS /home/osakanataro>

出力結果のcsvは、Windows上のPowerShellで実行した場合と同じ書式のモノとなりました。

$PSVersionTableの内容は下記のようになっていました。

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-alpha
PSEdition                      Core
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   3.0.0.0
GitCommitId                    v6.0.0-alpha.15
CLRVersion
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

以下はおまけ。
Microsoftのレポジトリとして指定されている「https://packages.microsoft.com/rhel/7/prod/」とか「https://packages.microsoft.com/config/rhel/7/」を見ていくとなかなか面白い
https://packages.microsoft.com/config/rhel/7/mssql-server.repo」という用にCentOS7向けのMSSQL Serverっぽいレポジトリファイルがある。RPMファイルは「https://packages.microsoft.com/rhel/7/mssql-server/」にある。

MSSQL Serverのインストール手順については「Install SQL Server on Linux」を参照のこと。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください