LoginSignup
16
9

More than 3 years have passed since last update.

PowerShellでImport-Module Appxしようとすると“Operation is not supported on this platform. (0x80131539)”

Posted at

概要

WindowsのPowerShell 7.1.0および7.1.3環境で Import-Module Appx しようとすると、以下のようにエラーになった。

PS> import-module appx
Import-Module: Operation is not supported on this platform. (0x80131539)

-usewindowspowershell オプションを使用することで Import-Module が(WARNINGがでるけど)成功し、AppxモジュールのAdd-AppxPackageコマンドレットを使うこともできた。

PS> Import-Module Appx -usewindowspowershell
WARNING: Module Appx is loaded in Windows PowerShell using WinPSCompatSession remoting session; please note that all input and output of commands from this module will be deserialized objects. If you want to load this module into PowerShell please use 'Import-Module -SkipEditionCheck' syntax.

経緯

Microsoft Storeの利用が禁止されている環境でWSL 2を構築しようとしてた。

基本的には「Windows Subsystem for Linux (WSL) を Windows 10 にインストールする | Microsoft Docs」の手動インストールの手順を実行していくのだけど、手順6でLinuxディストリビューションのインストールができない。そこで「Linux 用 Windows サブシステム (WSL) ディストリビューションを手動でダウンロードする | Microsoft Docs」を行う。

ディストリビューションをダウンロードしたら、インストールする。こんな感じだ(前期のページで指示されている)。

PS> Add-AppxPackage .\Ubuntu_2004.2020.424.0_x64.appx
Add-AppxPackage: The 'Add-AppxPackage' command was found in the module 'Appx', but the module could not be loaded. For more information, run 'Import-Module Appx'.

そのコマンドレットが含まれているモジュールをロードするために、まず Import-Module Appx しなさいと。じゃあそうしよう。

PS> Import-Module Appx
Import-Module: Operation is not supported on this platform. (0x80131539)

おや、これもエラーになるようだ。

PowerShell 7.1.0でImport-Module Appx

エラーメッセージやエラーコードなどで検索していくと、以下のGitHubイシューにたどりついた。

Powershell 7.1 preview 4 or 5で上記のエラーが発生したというものだ。次にように続いていた。

The module can be imported properly in Powershell 7.0.2 or, in Preview 4/5 using -UseWindowsPowerShell.
I was able to load the module till 7.1 Preview 3

そういうわけで -usewindowspowershell をスイッチを付けたところ Import-Module は成功したし Add-AppxPackage もできた。

PS> Import-Module Appx -usewindowspowershell
WARNING: Module Appx is loaded in Windows PowerShell using WinPSCompatSession remoting session; please note that all input and output of commands from this module will be deserialized objects. If you want to load this module into PowerShell please use 'Import-Module -SkipEditionCheck' syntax.
PS> Add-AppxPackage .\Ubuntu_2004.2020.424.0_x64.appx

これは恒久対策ではなさそうだけど、まだ現状の回避策みたいだ

上記のGitHubイシューは、このように動作することはわかってるのだけど「これが正しい使い方なの?」という相談で、これはバグだから修正されるべきだという方向に落ち着いているようだ。

SteveL-MSFT commented on 4 Sep 2020
@SeeminglyScience spoke with .NET team and based on your idea, they agreed that to maintain compatibility, they would expose both set_ and put_ accessors for WinRT microsoft/CsWinRT#402. Thanks!

SteveL-MSFT commented on 3 Oct 2020
Ok, after extensive discussions with .NET team and a change in their Windows.SDK assembly that handles WinRT calls to support both put_ and set_ for compatibility, the fix still requires Appx module to be retargeted for netstandard20. Working with the Appx team to do this. Since there is no change in PowerShell that can be done, closing this.

ただmicrosoft/CsWinRT#402はとりこまれずにクローズされたように見えるし、その後どうなったのだろうといぶかしんでいる人もいる。

asklar commented on 7 Jan
@SteveL-MSFT any updates on this? Still happening on 7.1.0

もしかしてそうは言いながらもう解決してないだろうかと、PowerShell v7.1.3に更新して試してみたけど、まだ変わってないみたいだった。

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
PS> Import-Module Appx
Import-Module: Operation is not supported on this platform. (0x80131539)
PS> Import-Module Appx -usewindowspowershell
WARNING: Module Appx is loaded in Windows PowerShell using WinPSCompatSession remoting session; please note that all input and output of commands from this module will be deserialized objects. If you want to load this module into PowerShell please use 'Import-Module -SkipEditionCheck' syntax.

もし何か情報をお持ちでしたら、ぜひお教えください。

参考

16
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
9