Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] New-PnpSite with Managed Identity gives "Object reference not set to an instance of an object. " but still creates the Site #4082

Open
2 of 6 tasks
CGrossNteam opened this issue Jul 9, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@CGrossNteam
Copy link

CGrossNteam commented Jul 9, 2024

Reporting an Issue or Missing Feature

I'm using the "New-PnPSite" cmdlet inside of a Runbook, which is used with a Managed Identity.

The Managed Idetity has the following Permissions:

  • Microsoft Graph [Directory.ReadWrite.All]
  • Microsoft Graph [Team.Create]
  • Microsoft Graph [Group.Create]
  • Microsoft Graph [TeamMember.ReadWrite.Al]
  • Office 365 SharePoint Online [Sites.FullControl.All]

I connect to the SharePoint Admin Site the following way:

$ConnectionAdminCenter = Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com" -ManagedIdentity -ReturnConnection

And then use the "New-PnpSite" cmdlet this way:

New-PnPSite -Type TeamSite -Alias "Site-Alias" -Title "Site-Name" -Description "Description" -Owners "owner@tenant.com" -Lcid 1031 -Wait -Connection $ConnectionAdminCenter

When I try to create a "TeamSiteWithoutMicrosoft365Group" it works without issue.

Expected behavior

The Site will be created with the parameters given. After that the runbook will continue with what comes afterwards.

Actual behavior

The Site is created and after about 10 minutes the Runbook shows the Status "Error" and in the "Exceptions" Tab I see:

Object reference not set to an instance of an object. (Object reference not set to an instance of an object.)

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

I'm running Version 2.5.12-nightly of the PnP.Module.

Which operating system/environment are you running PnP PowerShell on?

  • Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : please specify
@CGrossNteam CGrossNteam added the bug Something isn't working label Jul 9, 2024
@jackpoz
Copy link
Contributor

jackpoz commented Jul 9, 2024

Could you try passing -ErrorAction:Stop as additional parameter and then logging more exception details with Get-PnPException | Select-Object * ?

@CGrossNteam
Copy link
Author

This is the Exception I'm getting:

Message : Object reference not set to an instance of an object. Stacktrace : at PnP.PowerShell.Commands.NewSite.ExecuteCmdlet() in D:\a\powershell\powershell\src\Commands\Admin\NewSite.cs:line 145 at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in D:\a\powershell\powershell\src\Commands\Base\PnPConnectedCmdlet.cs:line 53 ScriptLineNumber : 160 InvocationInfo : System.Management.Automation.InvocationInfo Exception : System.NullReferenceException: Object reference not set to an instance of an object. at PnP.PowerShell.Commands.NewSite.ExecuteCmdlet() in D:\a\powershell\powershell\src\Commands\Admin\NewSite.cs:line 145 at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in D:\a\powershell\powershell\src\Commands\Base\PnPConnectedCmdlet.cs:line 53 CorrelationId : 01de3aa1-7025-9000-74f1-529dedd7ac88 TimeStampUtc : 7/10/2024 8:23:19 AM

@jackpoz
Copy link
Contributor

jackpoz commented Jul 10, 2024

That shows that it's line

WriteObject(returnedContext.Url);
and it happens because something else went wrong during the creation, with returnedContext being null.
Do you know if the site was created ?

@CGrossNteam
Copy link
Author

The site and the coresponding Group are being created.

I can navigate to it. The Owner is set.

But your comment brought me to a possible cause. The SharePoint is almost at its limit space wise. Could that cause the lead to the cmdlet not being able to find the URL after creation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants