ブラウザを開かずにshowroomを視聴する

ブラウザを開かずにshowroom liveを視聴する方法はないかなぁ・・・と調べて見たら、livestreamを使い視聴するためのscriptを発見。fcicq/showroomlive.sh

ただ、これはそのままではshowroomの仕様変更に対応しておらず使えない。また、livestreamは現在メンテナンスされておらずstreamlinkを使え、と書いてある。

streamlinkはpythonインストールとか考えなくても使えるようなWindows用バイナリが用意されているため、簡単に実験ができそうだったので試してみた。

とりあえずstreamlinkをインストールして、showroom liveの配信やってるページに出てくる.m3u8ファイルを与えてみると・・・

C:\Program Files (x86)\Streamlink\bin>streamlink.exe https://edge-210-140-227-26.showroom-live.com/liveedge/52e66cae6b58a08641bd702e091c7f94fee147899da1a714c38312bab75ea7f0/chunklist_w791438536.m3u8
[cli][info] Found matching plugin hls for URL https://edge-210-140-227-26.showroom-live.com/liveedge/52e66cae6b58a08641bd702e091c7f94fee147899da1a714c38312bab75ea7f0/chunklist_w791438536.m3u8
Available streams: live (worst, best)

C:\Program Files (x86)\Streamlink\bin>

高画質(best)/低画質(worst)の選択を求められた。

C:\Program Files (x86)\Streamlink\bin>streamlink.exe https://edge-210-140-227-26.showroom-live.com/liveedge/52e66cae6b58a08641bd702e091c7f94fee147899da1a714c38312bab75ea7f0/chunklist_w791438536.m3u8 worst
[cli][info] Found matching plugin hls for URL https://edge-210-140-227-26.showroom-live.com/liveedge/52e66cae6b58a08641bd702e091c7f94fee147899da1a714c38312bab75ea7f0/chunklist_w791438536.m3u8
[cli][info] Available streams: live (worst, best)
[cli][info] Opening stream: live (hls)
error: The default player (VLC) does not seem to be installed. You must specify the path to a player executable with --player.
[cli][info] Closing currently open stream...

C:\Program Files (x86)\Streamlink\bin>

VLCを使って動画再生を開始しようとしたが、VLCがインストールされていないため失敗した。

そこでVLCをインストールしてから再度実行してみると、こんどはVLCアプリが起動して再生が始まった。

C:\Program Files (x86)\Streamlink\bin>streamlink.exe https://edge-210-140-227-26.showroom-live.com/liveedge/52e66cae6b58a08641bd702e091c7f94fee147899da1a714c38312bab75ea7f0/chunklist_w791438536.m3u8 worst
[cli][info] Found matching plugin hls for URL https://edge-210-140-227-26.showroom-live.com/liveedge/52e66cae6b58a08641bd702e091c7f94fee147899da1a714c38312bab75ea7f0/chunklist_w791438536.m3u8
[cli][info] Available streams: live (worst, best)
[cli][info] Opening stream: live (hls)
[cli][info] Starting player: "C:\Program Files\VideoLAN\VLC\vlc.exe"
[cli][info] Player closed
[cli][info] Stream ended
[cli][info] Closing currently open stream...

C:\Program Files (x86)\Streamlink\bin>

(上記のログはVLCの終了までを含む)

さらにいろいろ実験中、うっかりとstreamlinkに対してルームのURLそのものを渡してしまったところ、何事もないかの表示表示された。

C:\Program Files (x86)\Streamlink\bin>streamlink.exe https://www.showroom-live.com/sena-hiiragi
[cli][info] Found matching plugin showroom for URL https://www.showroom-live.com/sena-hiiragi
Available streams: 144p (worst), low, 360p, high (best)

C:\Program Files (x86)\Streamlink\bin>
C:\Program Files (x86)\Streamlink\bin>streamlink.exe https://www.showroom-live.com/sena-hiiragi best
[cli][info] Found matching plugin showroom for URL https://www.showroom-live.com/sena-hiiragi
[cli][info] Available streams: 144p (worst), low, 360p, high (best)
[cli][info] Opening stream: high (rtmp)
[cli][info] Starting player: "C:\Program Files\VideoLAN\VLC\vlc.exe"
[cli][info] Player closed
[cli][info] Stream ended
[cli][info] Closing currently open stream...

C:\Program Files (x86)\Streamlink\bin>

「Opening stream: high (rtmp)」となっているが、この形式はFlash Video形式となる。デフォルトでは「”rtmp,hls,hds,http,akamaihd,*”」という順序で優先順位を決めているので、MPEG4-TS形式で受信するには「–stream-types=hls」オプションをつけてhlsを指定する必要がある。

C:\Program Files (x86)\Streamlink\bin>streamlink.exe --stream-types=hls https://www.showroom-live.com/sena-hiiragi best
[cli][info] Found matching plugin showroom for URL https://www.showroom-live.com/sena-hiiragi
[cli][info] Available streams: 144p (worst), 360p (best)
[cli][info] Opening stream: 360p (hls)
[cli][info] Starting player: "C:\Program Files\VideoLAN\VLC\vlc.exe"
[cli][info] Player closed
[cli][info] Stream ended
[cli][info] Closing currently open stream...

C:\Program Files (x86)\Streamlink\bin>

よくみたら「streamlinkのpluginページ」にshowroomが対応していると掲載されていた。

他にabematv、 bilibili、 nhkworld、pixiv(sketch)が掲載されていて興味深い。

で・・・ここで調べたことを元に、showroom liveで目的とするルームの配信が始まったらVLCを起動して視聴開始するためのPowerShellスクリプトを実装してみた。

https://github.com/osakanataro/showroom-live

なぜPowerShellで組んだかといえば、WindowsとLinuxの両方で同じスクリプトを使いたかったからですね。

プラットフォームの違いを考慮しなければならない点がいくつかありましたが、まぁなんとかなりました。

PowerCLIを使ってvSphere仮想マシンをテンプレートから連続デプロイ

RedHat OpenShift環境を作るためのansible hostsファイルがすごく難解。

おかげでいろんなhostsファイル記述を実験する羽目に・・・

仮想マシンテンプレートを作ったあと、仮想マシンのカスタマイズ仕様を元にデプロイするだけとは言え、マスタ2台、インフラノード2台、ノード2台とかを毎回作り直すのが面倒。

簡略化するためにPowerCLIを使って一括作成できるようなスクリプトを作成した。

$vcenter="testvcenter"       # 接続先vCenterホスト名 or IPアドレス
$vcenterusername="administrator@vsphere.local" # vCenterユーザ名
$vcenterpassword="test"       # vCenterパスワード
$vmtemplatename="rhel7-os311" # 仮想マシンテンプレート名
$vmcustomizespec="rhel7-base" # 仮想マシンのカスタマイズ仕様名
$datastore="vsphere10"          # デプロイ先データストア
$esxserver="172.17.44.10"       # デプロイ先ESXiサーバ
$subnetmask="255.255.0.0"       # 仮想マシンのサブネット
$defaultgw="172.17.0.1"         # 仮想マシンのデフォルトゲートウェイ

connect-vcenter -Server $vcenter -User $vcenterusername -Password $vcenterpassword -WarningAction 0

deployvm -vmname "master221" -ipaddr "172.17.44.221" -cpu 4 -memory 16
deployvm -vmname "master222" -ipaddr "172.17.44.222" -cpu 4 -memory 16
deployvm -vmname "infra-node223" -ipaddr "172.17.44.223" -cpu 2 -memory 8
deployvm -vmname "node224" -ipaddr "172.17.44.224" -cpu 2 -memory 8
deployvm -vmname "node225" -ipaddr "172.17.44.225" -cpu 2 -memory 8

Disconnect-VIServer -Confirm:$false


###########################################
### 関数名: connect-vcenter
### 役割:   指定したvCenterサーバに接続
### 入力: 「-Server vCenterサーバ名」 
###      「-User ユーザ名」
###      「-Password パスワード」 
###      「-Credential パスワードの暗号化文字列」
###       「-Password」か「-Credential」かは排他指定
### 注意: パイプライン処理不可
###########################################
function connect-vcenter{
    param(
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$Server,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$User,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$Password,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][SecureString]$Credential
    )

    # $global:DefaultVIServers が存在している場合はすでにvCenterに接続されているので処理を飛ばす
    #  vROpsと異なり接続がなくなったら変数もなくなるようだが、念のためこちらも接続中のユーザ名があることを確認
    if([String]::IsNullOrEmpty($global:DefaultVIServers.User)){
        Try {
            if($Credential){
                $pscredential=New-Object System.Management.Automation.PSCredential($User,$Credential)
                Connect-VIServer -Server $Server -Credential $pscredential -WarningAction 0 | Out-Null
                if($? -eq $false){ throw }
            }else{
                Connect-VIServer -Server $Server -User $User -Password $Password -WarningAction 0 | Out-Null
                if($? -eq $false){ throw }
            }
        } Catch {
            Write-Host "vCenterサーバへの接続に失敗しました"
            Write-Host $Error[0]
            exit 1
        }
    }
    return
}

###########################################
### 関数名: deployvm
### 役割:   仮想マシンテンプレートから仮想マシンをデプロイ
### 入力: 「-vmname 仮想マシンホスト名」 
###      「-ipaddr IPアドレス」
###      「-cpu CPU数」 
###      「-memory メモリ容量」
### 注意: 簡略化のため、下記の前提がある
###    デプロイ先のESXiサーバを、グローバル変数 $esxserver で指定していること
###    デプロイ先のデータストアを、グローバル変数 $datastore で指定していること
###    仮想マシンテンプレートを、グローバル変数 $vmtemplatename で指定していること(作成済みであること)
###    仮想マシンのカスタマイズ仕様を、グローバル変数 $vmcustomizespec で指定していること(作成済みであること)
###    グローバル変数で仮想マシンのサブネットマスク $subnetmask とデフォルトゲートウェイ $defaultgw を指定していること
###########################################
function deployvm{
    Param(
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$vmname,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][string]$ipaddr,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][int]$cpu,
        [Parameter(ValueFromPipeline=$false,Mandatory=$false)][int]$memory
    )
    Get-OSCustomizationSpec $vmcustomizespec | New-OSCustomizationSpec -Name vmtemp -Type NonPersistent
    Get-OSCustomizationNicMapping vmtemp | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ipaddr -SubnetMask $subnetmask -DefaultGateway $defaultgw
    Get-OSCustomizationSpec vmtemp | Set-OSCustomizationSpec -NamingScheme vm

    New-VM -Name $vmname -VMHost $esxserver -Template $vmtemplatename -OSCustomizationSpec vmtemp -Datastore $datastore -Confirm:$false
    Set-VM -VM $vmname -MemoryGB $memory -NumCpu $cpu -Confirm:$false
    Start-VM -VM $vmname -Confirm:$false
    Remove-OSCustomizationSpec vmtemp -Confirm:$false
}

なお、vCenterへの接続部分がごっつい関数にしてあるのは、他で使ったものの流用であるためです。

deployvmで行っていることの詳細については「PowerShellを使ってVMwareのテンプレートからデプロイで「既存のカスタマイズ仕様を使用してカスタマイズする」を行う方法」を参照のこと。

WindowsServer 2016にVMware PowerCLIをインストールする際のメモ

Windows Server 2016環境にVMware PowerCLIをインストールしたので、その手順のメモ
なお、2020年4月以降、PowerShell GalleryへのアクセスがTLS 1.2必須となったため、後半に書かれている対処方法を行う必要がある。

(1) PowerShellを起動

(2)「Install-Module -Name VMware.PowerCLI」を実行

途中、NuGetプロバイダーのインストールと、PowerCLIがあるレポジトリの追加が要求されるので、両方許可する。

Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS C:\Users\Administrator> Install-Module -Name VMware.PowerCLI

続行するには NuGet プロバイダーが必要です
PowerShellGet で NuGet ベースのリポジトリを操作するには、'2.8.5.201' 以降のバージョンの NuGet
プロバイダーが必要です。NuGet プロバイダーは 'C:\Program Files\PackageManagement\ProviderAssemblies' または
'C:\Users\Administrator\AppData\Local\PackageManagement\ProviderAssemblies'
に配置する必要があります。'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force' を実行して NuGet
プロバイダーをインストールすることもできます。今すぐ PowerShellGet で NuGet
プロバイダーをインストールしてインポートしますか?
[Y] はい(Y)  [N] いいえ(N)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"): y

信頼されていないリポジトリ
信頼されていないリポジトリからモジュールをインストールしようとしています。このリポジトリを信頼する場合は、Set-PSReposit
ory コマンドレットを実行して、リポジトリの InstallationPolicy の値を変更してください。'PSGallery'
からモジュールをインストールしますか?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "N"): y
PS C:\Users\Administrator>

(3) 以上!


なお、その後のメモ

自己証明書を使ってるvCenterサーバに接続しようとすると下記のエラーがでる。

PS C:\Users\Administrator> Connect-VIServer -Server vcenterサーバ -User administrator@vsphere.local -Password "パスワード"
Connect-VIServer : 2018/12/20 11:25:08  Connect-VIServer                Error: Invalid server certificate. Use Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Prompt if you'd like to connect once or to add a permanent exception for this server.
Additional Information: 機関 'vcenterサーバ' との SSL/TLS のセキュリティで保護されているチャネルに対する信頼関係を確立できませんでした。
発生場所 行:1 文字:1
+ Connect-VIServer -Server vcenterサーバ -User administrator@vsphere.loca ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : セキュリティ エラー: (: ) [Connect-VIServer]、ViSecurityNegotiationException
    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_CertificateError,VMware.VimAutomation.ViCore.
   Cmdlets.Commands.ConnectVIServer

PS C:\Users\Administrator>

以前は「」オプションで回避できていたが、今のPowerCLIでは「Set-PowerCLIConfiguration -InvalidCertificateAction Ignore」を設定する必要がある。(参考:New Release: VMware PowerCLI 10.0.0 )

Users\Administrator> Set-PowerCLIConfiguration -InvalidCertificateAction Ignore

Perform operation?
Performing operation 'Update PowerCLI configuration.'?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"): y

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecationWarnings WebOperationTimeout
                                                                                                  Seconds
-----    -----------     ------------------- ------------------------  -------------------------- -------------------
Session  UseSystemProxy  Multiple            Ignore                    True                       300
User                                         Ignore
AllUsers


PS C:\Users\Administrator>

これで接続できるようになる。

PS C:\Users\Administrator> Connect-VIServer -Server vCenterサーバ -User administrator@vsphere.local -Password "パスワード"

Name                           Port  User
----                           ----  ----
vCenterサーバ                    443   VSPHERE.LOCAL\Administrator

PS C:\Users\Administrator>

2020/07/16追記

久しぶりにやってみたら、以下のエラーになった。

PS C:\Users\Administrator> Install-Module -Name VMware.PowerCLI

続行するには NuGet プロバイダーが必要です
PowerShellGet で NuGet ベースのリポジトリを操作するには、'2.8.5.201' 以降のバージョンの NuGet
プロバイダーが必要です。NuGet プロバイダーは 'C:\Program Files\PackageManagement\ProviderAssemblies' または
'C:\Users\Administrator\AppData\Local\PackageManagement\ProviderAssemblies'
に配置する必要があります。'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force' を実行して NuGet
プロバイダーをインストールすることもできます。今すぐ PowerShellGet で NuGet
プロバイダーをインストールしてインポートしますか?
[Y] はい(Y)  [N] いいえ(N)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"):
警告: URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' から '' へダウンロードできません。
警告: 利用可能なプロバイダーの一覧をダウンロードできません。インターネット接続を確認してください。
PackageManagement\Install-PackageProvider : プロバイダー 'NuGet' について、指定された検索条件に一致するものが見つかりま
せんでした。パッケージ プロバイダーには 'PackageManagement' タグと 'Provider' タグが必要です。指定されたパッケージにこ
れらのタグがあるかどうかを確認してください。
発生場所 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7405 文字:21
+ ...     $null = PackageManagement\Install-PackageProvider -Name $script:N ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-Pac
   kageProvider]、Exception
    + FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackagePro
   vider

PackageManagement\Import-PackageProvider : プロバイダー名 'NuGet' について、指定された検索条件に一致するものが見つかり
ませんでした。'Get-PackageProvider -ListAvailable' を使用して、このプロバイダーがシステム上に存在するか確認してください
。
発生場所 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7411 文字:21
+ ...     $null = PackageManagement\Import-PackageProvider -Name $script:Nu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (NuGet:String) [Import-PackageProvider]、Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProv
   ider

警告: URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' から '' へダウンロードできません。
警告: 利用可能なプロバイダーの一覧をダウンロードできません。インターネット接続を確認してください。
PackageManagement\Get-PackageProvider : パッケージ プロバイダー 'NuGet' が見つかりません。まだインポートされていない可
能性があります。'Get-PackageProvider -ListAvailable' を実行してみてください。
発生場所 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7415 文字:30
+ ... tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...PackageProvider:GetPackageProvider) [Get-PackageProvi
   der], Exception
    + FullyQualifiedErrorId : UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPacka
   geProvider

Install-Module : NuGet ベースのリポジトリを操作するためには、NuGet プロバイダーが必要です。'2.8.5.201' 以降のバージョン
の NuGet プロバイダーがインストールされていることを確認してください。
発生場所 行:1 文字:1
+ Install-Module -Name VMware.PowerCLI
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Install-Module]、InvalidOperationException
    + FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Install-Module

PS C:\Users\Administrator>

しかし、該当サーバでブラウザから「https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409」にアクセスしてみると、正常にファイルが取得できる。

調べて見ると、TLS 1.2アクセス必須となったためのエラーのようである。
 MasayaSawada「NuGet がmsg:unabletodownload エラーでインストールできない!
 PowerShell devblog「PowerShell Gallery TLS Support

現状SSL3とTLS1のサポートとなっている設定をTLS1.2サポートにする、という設定変更を行うことになる。

現状値の確認と変更は下記の様に行う。

PS C:\Users\Administrator> [Net.ServicePointManager]::SecurityProtocol
Ssl3, Tls
PS C:\Users\Administrator> [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12
PS C:\Users\Administrator> [Net.ServicePointManager]::SecurityProtocol
Tls12
PS C:\Users\Administrator>

これを設定した後に「Install-Module -Name VMware.PowerCLI」を再実行することでダウンロードとインストールが実施されます。

なお、下記サイトに書かれている様に「[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12」というコマンドは保存されない設定を行うものであるため、PowerShell窓を閉じてしまうと元の設定に戻ります。
 しばたテックブログ「Windows PowerShellとTLS 1.2

Orange Pi 2/armbianでVMware PowerCLIが動いた

先日、「CentOS7環境にPowerShell CoreとVMware PowerCLIをインストール」で書いたように、普通のCentOS7環境でVMware PowerCLIを動かしてみた。

で、ラズパイの上でもPowerShell Coreは動く。
Running PowerShell Core on Raspberry Pi 2

arm32というくくりでは同じだけど、SoCがAllwinner H3のOrange Pi 2でPowerShell Coreが動くか、
また、VMware PowerCLIがインストールでき、仮想マシン操作を行えるかを確認してみた。

現時点では、ARM Linux向けにはtar.gzで固めたものしか出ていないのでgithubのPowerShell Releasesからlinux-arm32.tar.gzとなっているものを入手。

2018/07/13時点だと「wget https://github.com/PowerShell/PowerShell/releases/download/v6.1.0-preview.3/powershell-6.1.0-preview.3-linux-arm32.tar.gz」でダウンロードした。

これを~/powershellディレクトリに展開

# mkdir ~/powershell
# cd ~/powershell
# tar xfz ../powershell-6.1.0-preview.3-linux-arm32.tar.gz
#

そして、PowerShell Coreを実行

PS /root> uname -a
uname -a
Linux orangepi2 4.14.18-sunxi #24 SMP Fri Feb 9 16:24:32 CET 2018 armv7l GNU/Linux
PS /root> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.3
PSEdition                      Core
GitCommitId                    v6.1.0-preview.3
OS                             Linux 4.14.18-sunxi #24 SMP Fri Feb 9 16:24:3...
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


PS /root>

普通に動いているようだ。

続いて、PowerCLIのインストール

PS /root> Install-Module -Name VMware.PowerCLI

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this
repository, change its InstallationPolicy value by running the Set-PSRepository
 cmdlet. Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "N"):y
PS /root>

何事もなく終了。
モジュールの確認

PS /root> Install-Module -Name VMware.PowerCLI

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this
repository, change its InstallationPolicy value by running the Set-PSRepository
 cmdlet. Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "N"):y
PS /root>
PS /root> Get-Module                                                            
ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clea...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-T...
Script     1.1.7.0    PackageManagement                   {Find-Package, Fin...
Script     1.6.0      PowerShellGet                       {Find-Command, Fin...
Script     2.0.0      PSReadLine                          {Get-PSReadLineKey...


PS /root> Get-Module -ListAvailable


    Directory: /usr/local/share/powershell/Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     6.7.0.8... VMware.DeployAutomation             {Add-DeployRule, A...
Script     6.7.0.8... VMware.ImageBuilder                 {Add-EsxSoftwareDe...
Manifest   10.1.1.... VMware.PowerCLI
Script     6.7.0.8... VMware.Vim
Script     10.1.0.... VMware.VimAutomation.Cis.Core       {Connect-CisServer...
Script     10.0.0.... VMware.VimAutomation.Cloud          {Add-CIDatastore, ...
Script     10.1.0.... VMware.VimAutomation.Common
Script     10.1.0.... VMware.VimAutomation.Core           {Add-PassthroughDe...
Script     6.5.4.7... VMware.VimAutomation.HA             Get-DrmInfo
Script     7.5.0.8... VMware.VimAutomation.HorizonView    {Connect-HVServer,...
Script     10.0.0.... VMware.VimAutomation.License        Get-LicenseDataMan...
Script     10.1.0.... VMware.VimAutomation.Nsxt           {Connect-NsxtServe...
Script     10.0.0.... VMware.VimAutomation.PCloud         {Connect-PIServer,...
Script     10.1.0.... VMware.VimAutomation.Sdk
Script     10.0.0.... VMware.VimAutomation.Srm            {Connect-SrmServer...
Script     10.1.0.... VMware.VimAutomation.Storage        {Add-KeyManagement...
Script     1.2.0.0    VMware.VimAutomation.StorageUtility Update-VmfsDatastore
Script     10.1.0.... VMware.VimAutomation.Vds            {Add-VDSwitchPhysi...
Script     10.0.0.... VMware.VimAutomation.Vmc            {Connect-Vmc, Disc...
Script     10.0.0.... VMware.VimAutomation.vROps          {Connect-OMServer,...
Script     6.5.1.7... VMware.VumAutomation                {Add-EntityBaselin...


    Directory: /root/powershell/Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   1.1.0.0    Microsoft.PowerShell.Archive        {Compress-Archive,...
Manifest   3.0.0.0    Microsoft.PowerShell.Host           {Start-Transcript,...
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clea...
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {Get-Credential, G...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Format-List, Form...
Script     1.1.7.0    PackageManagement                   {Find-Package, Get...
Script     1.6.0      PowerShellGet                       {Install-Module, F...
Script     0.0        PSDesiredStateConfiguration         {ThrowError, Node,...
Script     2.0.0      PSReadLine                          {Get-PSReadLineKey...


PS /root>

で・・・画面は省略しますが、connect-viserverして、get-vmして、とか普通に動きました。

CentOS7環境にPowerShell CoreとVMware PowerCLIをインストール

以前、PowerShell CoreとVMware PowerCLI Coreに関する記事を書いた。
現在は、VMware PowerCLI Coreが標準のVMware PowerCLIに統合され、またインストール手法も変わっている。
そこで、久しぶりにインストールしてみた。

まずは「Linux への PowerShell Core のインストール」記載の手順に従いインストール

1. Microsoftレポジトリの登録
「curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo」

[root@centos7 ~]# curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /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     70      0  0:00:02  0:00:02 --:--:--    70
[packages-microsoft-com-prod]
name=packages-microsoft-com-prod
baseurl=https://packages.microsoft.com/rhel/7/prod/
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc
[root@centos7 ~]#

2. PowerShellのインストール
「yum install -y powershell」

[root@centos7 ~]# yum install -y powershell
読み込んだプラグイン:fastestmirror
Determining fastest mirrors
<略>
依存性を解決しました

================================================================================
 Package    アーキテクチャー
                   バージョン                 リポジトリー                 容量
================================================================================
インストール中:
 powershell x86_64 6.1.0~preview.2-1.rhel.7   packages-microsoft-com-prod  50 M
依存性関連でのインストールをします:
 libunwind  x86_64 2:1.2-2.el7                base                         57 k

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

総ダウンロード容量: 50 M
インストール容量: 50 M
<略>
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
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : 2:libunwind-1.2-2.el7.x86_64                    1/2
  インストール中          : powershell-6.1.0~preview.2-1.rhel.7.x86_64      2/2
  検証中                  : 2:libunwind-1.2-2.el7.x86_64                    1/2
  検証中                  : powershell-6.1.0~preview.2-1.rhel.7.x86_64      2/2

インストール:
  powershell.x86_64 0:6.1.0~preview.2-1.rhel.7

依存性関連をインストールしました:
  libunwind.x86_64 2:1.2-2.el7

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

これでPowerShellを「pwsh」で実行できるようになりました。

続いてvSphere環境をコントロールするためにPowerCLI
VMware PowerCLI 10.11

といっても、以前はパッケージをダウンロードしてインストールという形態だったものが、現状は、MicrosoftのPowerShellギャラリーに登録されています。
PowerShell Gallery「VMware.PowerCLI

インストール方法もとっても簡単。
「Install-Module -Name VMware.PowerCLI」を実行するだけ。
途中で「Untrusted repositoryからのインストールを行うか」という質問に「y」と答える必要があります。

[root@centos7 ~]# pwsh
PowerShell v6.1.0-preview.2
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /root> Install-Module -Name VMware.PowerCLI

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this
repository, change its InstallationPolicy value by running the Set-PSRepository
 cmdlet. Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "N"):y

<いろんなVMwareモジュールを追加インストール>

PS /root>

まずは、初期状態で読み込まれているモジュールを確認

PS /root> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clea...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-T...
Script     1.1.7.0    PackageManagement                   {Find-Package, Fin...
Script     1.6.0      PowerShellGet                       {Find-Command, Fin...
Script     1.2        PSReadLine                          {Get-PSReadlineKey...


PS /root>

現在使えるモジュールを確認。

PS /root> Get-Module -ListAvailable


    Directory: /usr/local/share/powershell/Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     6.7.0.8... VMware.DeployAutomation             {Add-DeployRule, A...
Script     6.7.0.8... VMware.ImageBuilder                 {Add-EsxSoftwareDe...
Manifest   10.1.1.... VMware.PowerCLI
Script     6.7.0.8... VMware.Vim
Script     10.1.0.... VMware.VimAutomation.Cis.Core       {Connect-CisServer...
Script     10.0.0.... VMware.VimAutomation.Cloud          {Add-CIDatastore, ...
Script     10.1.0.... VMware.VimAutomation.Common
Script     10.1.0.... VMware.VimAutomation.Core           {Add-PassthroughDe...
Script     6.5.4.7... VMware.VimAutomation.HA             Get-DrmInfo
Script     7.5.0.8... VMware.VimAutomation.HorizonView    {Connect-HVServer,...
Script     10.0.0.... VMware.VimAutomation.License        Get-LicenseDataMan...
Script     10.1.0.... VMware.VimAutomation.Nsxt           {Connect-NsxtServe...
Script     10.0.0.... VMware.VimAutomation.PCloud         {Connect-PIServer,...
Script     10.1.0.... VMware.VimAutomation.Sdk
Script     10.0.0.... VMware.VimAutomation.Srm            {Connect-SrmServer...
Script     10.1.0.... VMware.VimAutomation.Storage        {Add-KeyManagement...
Script     1.2.0.0    VMware.VimAutomation.StorageUtility Update-VmfsDatastore
Script     10.1.0.... VMware.VimAutomation.Vds            {Add-VDSwitchPhysi...
Script     10.0.0.... VMware.VimAutomation.Vmc            {Connect-Vmc, Disc...
Script     10.0.0.... VMware.VimAutomation.vROps          {Connect-OMServer,...
Script     6.5.1.7... VMware.VumAutomation                {Add-EntityBaselin...


    Directory: /opt/microsoft/powershell/6.1.0~preview.2/Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   1.1.0.0    Microsoft.PowerShell.Archive        {Compress-Archive,...
Manifest   3.0.0.0    Microsoft.PowerShell.Host           {Start-Transcript,...
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clea...
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {Get-Credential, G...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Format-List, Form...
Script     1.1.7.0    PackageManagement                   {Find-Package, Get...
Script     1.6.0      PowerShellGet                       {Install-Module, F...
Script     0.0        PSDesiredStateConfiguration         {Get-PublicKeyFrom...
Script     1.2        PSReadLine                          {Get-PSReadlineKey...


PS /root>

以前、「PowerCLIとPowerCLI Coreの双方で動くPowerShellスクリプトの作り方」では、それぞれでモジュール名が異なっていた。
PowerCLI Coreでのモジュール名変更は無かったことになった模様。

とりあえず、VI-Connectで接続をかけてみる・・・

PS /root> Connect-VIServer -Server IPアドレス -User root -Password password -WarningAction 0
Connect-VIServer : 2018/07/06 14:29:03  Connect-VIServer                Error: Invalid server certificate. Use Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Ignore to ignore the certificate errors for this connection.
Additional Information: Could not establish trust relationship for the SSL/TLS secure channel with authority 'IPアドレス'.
At line:1 char:1
+ Connect-VIServer -Server IPアドレス -User root -Password password - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : SecurityError: (:) [Connect-VIServer], ViSecurityNegotiationException
+ FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_CertificateError,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer

PS /root>

おや?
デフォルト証明書の場合の取り扱いが変わった模様。

VMware PowerCLI Blog「New Release: VMware PowerCLI 10.0.0」の「Default Certificate Handling」に記載がある。

エラーメッセージもあるように「Set-PowerCLIConfiguration -InvalidCertificateAction Ignore」を実行して無視するようにする、と。

PS /root> Set-PowerCLIConfiguration -InvalidCertificateAction Ignore

Perform operation?
Performing operation 'Update PowerCLI configuration.'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "Y"):y

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayD
                                                                       eprecati
                                                                       onWarnin
                                                                       gs
-----    -----------     ------------------- ------------------------  --------
Session  UseSystemProxy  Multiple            Ignore                    True
User                                         Ignore
AllUsers


PS /root>

改めて接続を実行

PS /root> Connect-VIServer -Server IPアドレス -User root -Password password   
Name                           Port  User
----                           ----  ----
IPアドレス                     443   root


PS /root>

問題なく動作しましたね。