pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
990 stars 663 forks source link

Issue - Get-PnPSiteDesign Get-PnPSiteScript #2002

Open ypcode opened 5 years ago

ypcode commented 5 years ago

Reporting an Issue or Missing Feature

I get an issue when I try either Get-PnPSiteDesign or Get-PnPSiteScript in order the get the list of designs (or scripts) I tried as well specifying the Id of script or design but get the same NullReferenceException

Expected behavior

Get the list of site designs and site scripts in my tenant

Actual behavior

image

image

Steps to reproduce behavior

Connect-PnPOnline https://tenant.sharepoint.com -UseWebLogin
Get-PnPSiteDesign
# ERROR
Get-PnPSiteScript
# ERROR
Get-PnPSiteScript -Identity <id_of_my_script>
# ERROR

Which version of the PnP-PowerShell Cmdlets are you using?

What is the version of the Cmdlet module you are running?

The latest march 2019 release ModuleType Version Name ExportedCommands


Binary 3.7.1903.0 SharePointPnPPowerShellOnline

How did you install the PnP-PowerShell Cmdlets?

ypcode commented 5 years ago

FYI, I just noticed that only happens when I connect using WebLogin (with my admin account), with direct credentials, it works just fine

sionjlewis commented 4 years ago

I can confirm that I'm seeing the same error when using UserWebLogin

Connect-PnPOnline -Url "https://<TENANT>.sharepoint.com/<PATH>/<SITE>" -UseWebLogin;
Get-PnPConnection;

The error message returned is:

Get-PnPSiteDesign : The remote server returned an error: (403) Forbidden. At line:1 char:1

  • Get-PnPSiteDesign
  • 
    + CategoryInfo          : NotSpecified: (:) [Get-PnPSiteDesign], WebException
    + FullyQualifiedErrorId : System.Net.WebException,SharePointPnP.PowerShell.Commands.GetSiteDesign

But it works fine when using Credentials

Connect-PnPOnline -Url "https://<TENANT>.sharepoint.com/<PATH>/<SITE>" -Credentials (Get-Credential);
Get-PnPConnection;

Is there any progress in a fix?

UPDATE #1 - WORK AROUND

To get the Get-PnPConnection to work with UserWebLogin you need to connect to your SharePoint Admin site like so:

Connect-PnPOnline -Url "https://<TENANT>-admin.sharepoint.com" -UseWebLogin;
Get-PnPConnection;

This does mean that PnP example below is not good, as you would applying the site design to the SharePoint Admin Center...

Get-PnPSiteDesign | ?{$_.Title -eq "Demo"} | Invoke-PnPSiteDesign

Instead you could do something like this:

Connect-PnPOnline -Url "https://<TENANT>-admin.sharepoint.com" -UseWebLogin;
$siteDesign = Get-PnPSiteDesign | ?{$_.Title -eq $row.SiteDesignName};
Invoke-PnPSiteDesign -Identity $siteDesign.Id -WebUrl "https://<TENANT>.sharepoint.com/<PATH>/<SITE>";

Noting forgetting to disconnect of cause :)

Disconnect-PnPOnline;

Update #2

Apparently Add-PnPSiteDesignTask has superseded the above CmdLet, see Microsoft's documentation for more info: https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/add-pnpsitedesigntask?view=sharepoint-ps