Today I tried to install PnPPowerShell within an Azure PowerShell Environment. In the past I tried just to copy all files in a folder within my Azure environment and user $env:PSModulePath to include the PowerShell Module.

But now that it is possible to use Install-Module within a normal PowerShell session you would hope that this would work in Azure as well. So you would run something like this:

Install-Module -Name "SharePointPnPPowerShell2016"

The above does need adjusting if you happen to user PnP PowerShell for SharePoint Online or SharePoint 2013.

When you run the above however you will get warnings about having to run as an administrator. As you don’t have control over this in Azure you will have to install the solution with -Scope CurrentUser. But that is not all. If you run

Install-Module -Name "SharePointPnPPowerShell2016" -Scope CurrentUser

You would be getting the following:

To avoid this you will need to include  -Confirm:$false -Force. 

 

This now results in:

Install-Module -Name "SharePointPnPPowerShell2016" -Scope CurrentUser -Confirm:$false -Force

The installer now runs within my PowerShell ISE without any prompts:

Time to get this to run in Azure PowerShell. Nothing can go wrong can it?

But When I run this the logs are telling me otherwise.

2017-12-07T09:42:48.4037683Z ##[error]Exception calling “ShouldContinue” with “2” argument(s): “Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available.”

Then I found a post on github with a similar error.

So I included the following line in my script.

Install-PackageProvider nuget -force

But now I’m back t the admin errors that I first got.

2017-12-07T09:48:09.5315733Z ##[error]Administrator rights are required to install packages in ”. Log on to the computer with an account that has Administrator rights, and then try again, or install in ‘C:\Users\buildguest\AppData\Local\PackageManagement\ProviderAssemblies’ by adding “-Scope CurrentUser” to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator)

 

So yet again I’m adding the -Scope CurrentUser to my Install-Package command as well.

And this time I’ve got more luck:

2017-12-07T09:53:07.0540621Z ##[error]Parameter set cannot be resolved using the specified named parameters.

This might look like things haven’t worked but it is simply a matter of the Connect-PnPOnline command returning an error, once I add the Url and my credentials to my Connect-PnPOnline all is working fine.

 

 

 

Advertisements