鍋綿ブログ

C#・SharePoint・SharePoint Framework・Office365を中心に扱うブログです。

PnP PowerShellをレガシーバージョンからアップグレードしよう!

 PnP、使ってますか!?私は使ってます。特に↓コレ。開発環境を作って本番環境に展開、なんて時にはこれが無いとやってられません。

www.micknabewata.com

 

 さてこのPnP、アップデートを怠っていると実行時にこんな警告が出ませんか?

You are running the legacy version of PnP PowerShell.

This version will be archived soon which means that while staying available, no updates or fixes will be released.
Consider installing the newer prereleased cross-platform version of PnP PowerShell.
This version has numerous improvements and many more cmdlets available.
To install the new version:

Uninstall-Module -Name SharePointPnPPowerShellOnline -AllVersions -Force
Install-Module -Name PnP.PowerShell

Read more about the new cross-platform version of PnP PowerShell at

https://pnp.github.io/powershell

To hide this message set the environment variable PNPLEGACYMESSAGE to "false"
In PowerShell add $env:PNPLEGACYMESSAGE='false' to your profile. Alternatively use 'Connect-PnPOnline -Url
[yoururl] -WarningAction Ignore'

 

どうもモジュールが変わっているようです。最新バージョンへのアップグレードが必要です。

 

レガシーバージョンからのアップグレード方法

 簡単です。PowerShellを管理者モードで起動し、旧モジュールをアンインストールしてから新モジュールをインストールするだけです。

Uninstall-Module -Name "SharePointPnPPowerShellOnline" -AllVersions -Force

Install-Module -Name "PnP.PowerShell"

 インストールが終わったら認証を通しておきます。

Register-PnPManagementShellAccess

レガシーバージョンからの変更点

 一部コマンドが削除されたり、名称変更があったりといくつか差異があります。以下のページで確認してください。

https://pnp.github.io/powershell/articles/upgrading.html

トラブルシューティング

Connect-PnPOnlineに失敗する

 認証を通していないと以下のエラーが出ます。Register-PnPManagementShellAccess コマンドで認証を通しておく必要があります。

The user or administrator has not consented to use the application with ID '31359c7f-bd7e-475c-86db-fdb8c937548e' named 'PnP Management Shell'. Send an interactive authorization request for this user and resource.

コマンドが見つからない

 レガシーバージョンのコマンドは一部削除されたり名称が変更したりされています。これらのコマンドは以下のように実行に失敗します。

Apply-PnPProvisioningTemplate : 用語 'Apply-PnPProvisioningTemplate' は、コマンドレット、関数、スクリプト ファイル、または操作可能なプログラムの名前として認識されません。名前が正しく記述されていることを確認し、パスが含まれている場合はそのパスが正しいことを確認してから、再試行してください。 

 詳細は以下のページで確認してください。

https://pnp.github.io/powershell/articles/upgrading.html