環境
- Windows Server 2016 Std (10.0.14393)
- PowerShell Version : 5.1.14393.3471
最終的な対処方法
PowerShell 7.0 (PowerShell Core) をインストールして、そちらで PowerCLI をインストールするか (但し Image Builder など一部は利用できない)、
PowerShellGet と PackageManagement のモジュールをデフォルトの Ver 1.0.0.1 からそれぞれ最新に更新する事で PowerShellGallery の利用が可能に戻りました。
2020/5/18 追記
本事象の根本原因が 4月以降、PowerShell Gallery にて TLS 1.0 / 1.1 での接続を非サポートとし、TLS 1.2 を必須とする変更が入ったことが原因だったようなので、
TLS 1.2 の指定方法などを別記事でまとめました。急ぎ修正する場合は TLS 1.2 を指定して、 Install-Module のオプションで -SkipPublisherCheck を指定することで回避は出来ます。恒久的には TLS1.2 を既定にして、PowerShellGet もアップデートすることが推奨されます。
2020/5/18 追記
本事象の根本原因が 4月以降、PowerShell Gallery にて TLS 1.0 / 1.1 での接続を非サポートとし、TLS 1.2 を必須とする変更が入ったことが原因だったようなので、
TLS 1.2 の指定方法などを別記事でまとめました。急ぎ修正する場合は TLS 1.2 を指定して、 Install-Module のオプションで -SkipPublisherCheck を指定することで回避は出来ます。恒久的には TLS1.2 を既定にして、PowerShellGet もアップデートすることが推奨されます。
事象
既存の PowerCLI を削除後、最新バージョンをインストールしようと Install-Module コマンドを叩くとエラーが...いったん既存バージョンの PowerCLI を削除し、
1 2 3 |
# インストール済みの VMware と頭につくモジュールを全て削除 PS C:\> Get-Module -Name VMware.* -ListAvailable | Uninstall-Module -Force |
最新バージョンを PowerShellGallery からインストールしようとしたらリポジトリが利用できないとエラーが...
1 2 3 4 5 6 7 8 9 10 |
# PowerShell をインストールするがエラー PS C:\> Install-Module -Name Vmware.PowerCLI PackageManagement\Install-Package : 指定された検索条件とパッケージ名 'Vmware.PowerCLI' と一致するものが見つかりませんでした。登録されている使用可能なすべ 発生場所 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 文字:21 + ... $null = PackageManagement\Install-Package @PSBoundParameters + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage |
Get-PSRepository で現在のリポジトリの登録を見てみるとデフォルトの PowerShellGallery が登録されていますが、Install-Module や Find-Module などが機能せず、リポジトリの再登録などもNG。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# リポジトリはデフォルトの PowerShellGallery が登録されている PS C:\> Get-PSRepository Name InstallationPolicy SourceLocation ---- ------------------ -------------- PSGallery Untrusted https://www.powershellgallery.com/api/v2 # いったんリポジトリを削除 PS C:\> Get-PSRepository | Unregister-PSRepository PS C:\> Get-PSRepository 警告: パッケージ ソースが見つかりません。 # デフォルトでリポジトリ登録するも登録できない PS C:\> Register-PSRepository -Default PS C:\> Get-PSRepository 警告: パッケージ ソースが見つかりません。 # ソースを指定して実行するも登録エラー PS C:\Users\Administrator> Register-PSRepository -Name PSGallery -SourceLocation https://www.powershellgallery.com/api/v2/ -PublishLocation https://www.powershellgallery.com/api/v2/package/ -ScriptSourceLocation https://www.powershellgallery.com/api/v2/items/psscript/ -ScriptPublishLocation https:// www.powershellgallery.com/api/v2/package/ -InstallationPolicy Trusted -PackageManagementProvider NuGet Get-PSGalleryApiAvailability : PowerShell ギャラリーは現在利用できません。後でやり直してください。 発生場所 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4057 文字:9 + Get-PSGalleryApiAvailability -Repository $Name + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [ Get-PSGalleryApiAvailability ]、InvalidOperationException + FullyQualifiedErrorId : PowerShellGalleryUnavailable, Get-PSGalleryApiAvailability Register-PSRepository : 'Register-PSRepository -Default' を使用して PSGallery リポジトリを登録します。 発生場所 行:1 文字:1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (PSGallery:String) [ Register-PSRepository ]、ArgumentException + FullyQualifiedErrorId : UseDefaultParameterSetOnRegisterPSRepository, Register-PSRepository |
対処方法1 : PowerShell 7.0 (PowerShell Core) をインストールして 7.0 上で PowerCLI をインストールしてみる
GitHub から最新版の PowerShell 7.0 のインストーラをダウンロード、PowerShell 5.1 と併用してみました。https://github.com/PowerShell/PowerShell
結論は PowerShell 7.0 の環境ではあっさりと PowerShellGallery からインストールができました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
PS C:\> $PSVersionTable Name Value ---- ----- PSVersion 7.0.0 PSEdition Core GitCommitId 7.0.0 OS Microsoft Windows 10.0.14393 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0 PS C:\> Get-PSRepository WARNING: Unable to find module repositories. # リポジトリはデフォルトで設定が一発完了 PS C:\Users\Administrator> Register-PSRepository -Default PS C:\Users\Administrator> Get-PSRepository Name InstallationPolicy SourceLocation ---- ------------------ -------------- PSGallery Untrusted https://www.powershellgallery.com/api/v2 # Find-Module は正常に認識 PS C:\> Find-Module -Name Vmware.powercli Version Name Repository Description ------- ---- ---------- ----------- 12.0.0.15947286 VMware.PowerCLI PSGallery This Windows PowerShell module contains … # Install-Module も問題なく一発完了 PS C:\Users\Administrator> 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" ): A # 無事に PowerCLI 12 がインストールできました。 PS C:\> Get-Module -Name Vmware.* -ListAvailable Directory: C:\Users\Administrator\Documents\PowerShell\Modules ModuleType Version PreRelease Name PSEdition ExportedCommands ---------- ------- ---------- ---- --------- ---------------- Script 12.0.0.15… VMware.CloudServices Desk { Connect-Vcs , Get-VcsOrganizationRole , … Script 7.0.0.159… VMware.DeployAutomation Desk { Add-DeployRule , Add-ProxyServer , Add-S … Script 7.0.0.159… VMware.ImageBuilder Desk { Add-EsxSoftwareDepot , Add-EsxSoftwareP … Manifest 12.0.0.15… VMware.PowerCLI Desk Script 7.0.0.159… VMware.Vim Desk Script 12.0.0.15… VMware.VimAutomation.Cis.Core Desk { Connect-CisServer , Disconnect-CisServe … Script 12.0.0.15… VMware.VimAutomation.Cloud Desk { Add-CIDatastore , Connect-CIServer , Dis … Script 12.0.0.15… VMware.VimAutomation.Common Desk { Get-Task , New-OAuthSecurityContext , St … Script 12.0.0.15… VMware.VimAutomation.Core Desk { Add-PassthroughDevice , Add-VirtualSwit … Script 12.0.0.15… VMware.VimAutomation.Hcx Desk { Connect-HCXServer , Disconnect-HCXServe … Script 7.12.0.15… VMware.VimAutomation.HorizonView Desk { Connect-HVServer , Disconnect-HVServer } Script 12.0.0.15… VMware.VimAutomation.License Desk Get-LicenseDataManager Script 12.0.0.15… VMware.VimAutomation.Nsxt Desk { Connect-NsxtServer , Disconnect-NsxtSer … Script 12.0.0.15… VMware.VimAutomation.Sdk Desk Get-ErrorReport Script 12.0.0.15… VMware.VimAutomation.Security Desk { Add-AttestationServiceInfo , Add-KeyPro … Script 11.5.0.14… VMware.VimAutomation.Srm Desk { Connect-SrmServer , Disconnect-SrmServe … Script 12.0.0.15… VMware.VimAutomation.Storage Desk { Add-EntityDefaultKeyProvider , Add-KeyM … Script 1.3.0.0 VMware.VimAutomation.StorageUtility Desk Update-VmfsDatastore Script 12.0.0.15… VMware.VimAutomation.Vds Desk { Add-VDSwitchPhysicalNetworkAdapter , Ad … Script 12.0.0.15… VMware.VimAutomation.Vmc Desk { Add-VmcSddcHost , Connect-Vmc , Disconne … Script 12.0.0.15… VMware.VimAutomation.vROps Desk { Connect-OMServer , Disconnect-OMServer , … Script 12.0.0.15… VMware.VimAutomation.WorkloadManag… Desk { Get-WMNamespace , Get-WMNamespacePermis … Script 6.5.1.786… VMware.VumAutomation Desk { Add-EntityBaseline , Copy-Patch , Get-Ba … |
デフォルトの PowerShell 5.1 のものより当然新しい。
1 2 3 4 5 6 7 8 9 10 11 12 |
PS C:\> Get-Module PowerShellGet -list | Select-Object Name,Version,Path Name Version Path ---- ------- ---- PowerShellGet 2.2.3 C:\program files\powershell\7\Modules\PowerShellGet\PowerShellGet.psd1 PS C:\> Get-Module PackageManagement -list | Select-Object Name,Version,Path Name Version Path ---- ------- ---- PackageManagement 1.4.6 C:\program files\powershell\7\Modules\PackageManagement\PackageManagement.psd1 |
※ 但し、PowerShell Core にインストールした PowerCLI は Image Builder など一部機能が利用できないので注意
対処方法2 : PowerShell 5.1 のまま、PowerShellGet など PowerShellGallery の利用に関するモジュールを最新にしてみる
PowerShell 5.1 環境のデフォルトの PowerShellGet などのモジュールが古く(Ver 1.0.0.1)悪さしているっぽいので更新版を PowerShellGallery からインストールします。
PowerShellGet などプリインストールされたものは Update-Module では更新できないので Install-Module を利用して最新版を追加インストールします。
但し、今は TLS の問題でその Install-Module も使えない状況なので、まずは TLS 1.2 での通信を有効にして、その状態で PowerShellGet を更新します。
※ 公式手順が MS Blog にありましたのでリンクを追記します (2022/11/03)
1 2 3 4 5 6 7 8 9 10 |
# 現在のプロトコルのセキュリティレベルを確認 PS C:\> [Net.ServicePointManager] ::SecurityProtocol Ssl3, Tls # TLS 1.2 を指定 PS C:\> [Net.ServicePointManager] ::SecurityProtocol = [Net.SecurityProtocolType] ::Tls12 PS C:\> [Net.ServicePointManager] ::SecurityProtocol Tls12 |
TLS 1.2 が使えれば Install-Module も使えますが、今後 TLS 1.2 をデフォルトで利用する最新の PowerShellGet にしておくと便利なので更新します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 現在(プリインストール)の PowerShellGet,PackageManagement のバージョンを確認 PS C:\> Get-Module PowerShellGet,PackageManagement -ListAvailable ディレクトリ: C:\Program Files\WindowsPowerShell\Modules ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Binary 1.0.0.1 PackageManagement {Find-Package, Get-Package , Get-PackageProvider , Get-Packa ... Script 1.0.0.1 PowerShellGet {Install-Module, Find-Module, Save-Module, Update-Module ...} # PowerShellGet を更新 (プリインストールのものは Update-Module ではなく Install-Module に -AllowClobber オプションを使う) PS C:\> Install-Module PowerShellGet -AllowClobber -Force # インストールされたバージョンを確認 # Update-Module ではないので更新さらたバージョンと旧バージョンが両方確認出来る PS C:\> Get-Module PowerShellGet,PackageManagement -ListAvailable ディレクトリ: C:\\Documents\WindowsPowerShell\Modules ModuleType Version Name ExportedCommand ---------- ------- ---- ---------------- Script 1.4.8.1 PackageManagement {Find-Package, Get-Package , Get-PackageProvider , Get-Packa ... Script 2.2.5 PowerShellGet {Find-Command, Find-DSCResource, Find-Module, Find-RoleCap... ディレクトリ: C:\Program Files\WindowsPowerShell\Modules ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Binary 1.0.0.1 PackageManagement {Find-Package, Get-Package , Get-PackageProvider , Get-Packa ... Script 1.0.0.1 PowerShellGet {Install-Module, Find-Module, Save-Module, Update-Module ...} |
PowerShellGet が更新できればその後は PowerShell Gallery などへの接続は TLS 1.2 を利用するようになります。
インターネット非接続環境での PowerShellGet の更新
インターネットに接続出来ない環境ではダウンロードして手動で置き換えました。
※ 但しこの手順多分無理なりなので正式かどうかわかりません。作業用環境で一時的に使えるようにする必要があるだけの時に試した手順なのでご了承下さい。
1 2 3 4 5 6 7 8 9 10 |
Get-Module PowerShellGet,PackageManagement -ListAvailable ディレクトリ: C:\Program Files\WindowsPowerShell\Modules ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Binary 1.0.0.1 PackageManagement {Find-Package, Get-Package , Get-PackageProvider , Get-Packa ... Script 1.0.0.1 PowerShellGet {Install-Module, Find-Module, Save-Module, Update-Module ...} |
https://www.powershellgallery.com/packages/PackageManagement/
PowerShellGet も以下から最新安定板をダウンロード
https://www.powershellgallery.com/packages/PowerShellGet
ダウンロードしたパッケージ (NuGet Package) の拡張子 .nupkg を拡張子 .zip に変更し解凍、解凍したフォルダを [C:\Program Files\WindowsPowerShell\Modules\] 配下の PackageManagement と PowerShellGet の中にコピー。
※古いバージョンのフォルダは頭にアンダースコアつけて退避。
配置したモジュールが読み込めるか確認します。
1 2 3 4 5 6 7 8 9 10 11 |
PS C:\> Get-Module PackageManagement -list | Select-Object Name,Version,Path Name Version Path ---- ------- ---- PackageManagement 1.4.7 C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\PackageManagement.psd1 PS C:\> Get-Module PowerShellGet -list | Select-Object Name,Version,Path Name Version Path ---- ------- ---- PowerShellGet 2.2.4.1 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.4.1\PowerShellGet.psd1 |
1 2 |
# リポジトリは -Default で PowerShellGallery を登録 PS C:\Users\Administrator> Register-PSRepository -Default |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
PS C:\> Get-PSRepository 警告: MSG:UnableToDownload «https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409» «» 警告: Unable to download the list of available providers. Check your internet connection. Name InstallationPolicy SourceLocation ---- ------------------ -------------- PSGallery Untrusted https://www.powershellgallery.com/api/v2 # Find-Module で最新版の PowerCLI を確認 PS C:\> Find-Module -Name VMware.Powercli Version Name Repository Description ------- ---- ---------- ----------- 12.0.0.15947286 VMware.PowerCLI PSGallery This Windows PowerShell module contains VMware.PowerCLI # Install-Module で PowerCLI を問題なくインストール完了 PS C:\> 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] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S) [?] ヘルプ (既定値は "N" ): A |
作業環境などで Windows 2016 など最新でない踏み台サーバーに PowerCLI をインストールするときなどに参考にして下さい。
0 件のコメント:
コメントを投稿