SharePointCommunity
Die deutschsprachige Community für SharePoint, Microsoft 365, Teams, Yammer und mit Azure

Sponsored by

Willkommen im Forum Archiv.
Einträge sind hier nicht mehr möglich, aber der Bestand von 12 Jahren SharePoint-Wissen ist hier recherchierbar.




SharePoint Online Powershell - Context.Web.EnsureUser() fails randomly

Unbeantwortet Dieser Beitrag hat 0 Antworten

Ohne Rang
59 Beiträge
Simb55 erstellt 14 Nov. 2019 16:00
SchlechtSchlechtIn OrdnungIn OrdnungDurchschnittDurchschnittGutGutSehr gutSehr gut

Hello there,

I'm writing a PowerShell script, that is supposed to create an Azure AD Security Group and to invite some guest users  to our tenant and add them to the group. Also, the data shall be written to different SharePoint Online lists.

Here is a screenshot of my code

Note:

- $context has been initialised successfully beforehand

- Connect-AzureAD has been executed successfully beforehand

 

If I run this in the context of the rest of my code, 80% of the time, it throws the following error:

"The User TestCompany cannot be found"

If I rerun only those few lines marked in yellow on the first screenshot after my script is finished, it works flawlessly and a SharePoint List Item is created.

 

Judging from the outcome, I would consider my script to be correct. What I do not understand is, why it fails when running in the context of the rest of the script. I thought it would maybe take some time for the group to be created, so I added the Start-Sleep for 60s, but that doesn't seem to be the case, since I can see the group created in Azure AD, as soon as the New-AzureADGroup cmdlet is executed.

Any help would be greatly appreciated.