3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PnP.PowerShell2.xでConnect-PnPOnlineを実行したらエラーが発生した

Posted at

備忘録として

PnP.PowerShellを2.1.1にアップデートし、Connect-PnPOnlineを実行した。

Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/Site01 -Interactive

するとエラーが発生した。

Connect-PnPOnline : 'Connect-PnPOnline' コマンドはモジュール 'PnP.PowerShell' で見つかりましたが、このモジュールを読み
込むことができませんでした。詳細については、'Import-Module PnP.PowerShell' を実行してください。
発生場所 行:1 文字:1
+ Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/Site01 -I ...
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Connect-PnPOnline:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
    + FullyQualifiedErrorId : CommandNotFoundException

詳細については、'Import-Module PnP.PowerShell' を実行してください。となっているので実行した。

Import-Module PnP.PowerShell

別のエラーメッセージが表示された。

Import-Module : ファイルまたはアセンブリ 'System.Management.Automation, Version=7.2.0.0, Culture=neutral, PublicKeyToke
n=31bf3856ad364e35'、またはその依存関係の 1 つが読み込めませんでした。指定されたファイルが見つかりません。
発生場所 行:1 文字:1
+ Import-Module PnP.PowerShell
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand

なんで??と思って調べていたら環境のせいだった。
(先輩、ご指摘ありがとうございます)
PnP.PowerShell2.xはPowerShell 7.2.x 以降のバージョンでのみ動く、とのこと。
参照)Updating from PnP PowerShell 1.x to 2.x

自分の端末のPowerShellのバージョンは5.1。
WindowsUpdateを実行していれば自動でPowerShellの最新バージョンに更新されるものと思い込んでいた。

Powershellを7.3.3にしたらきちんと実行できた。

※.NET 6.0以降をインストールする必要があります。
 接続は問題ないが、他の命令文で警告が表示されます。
 (Runtimeだけでもインストールすれば警告が表示されなくなります)

3
0
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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?