[Question] Add-PnPGroupMember not working in Azure Function #3125
Unanswered
kbeeveer46
asked this question in
Q&A
Replies: 1 comment
-
I figured out how to do it using this code. Is there a cleaner way? What if I don't know the object id at runtime?
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm upgrading our scripts from SharePointPnPPowerShellOnline to PnP.PowerShell and I'm trying to upgrade the following code that adds an Office 365 group to a SharePoint group
Add-PnPUserToGroup -LoginName "GroupName@xxx.onmicrosoft.com" -Identity "Site Title Visitors"
I tried several different variations of the new way of doing it and I'm getting a "user not found" error for each one. The Azure Function is using runtime 4.21.1.20667, PowerShell 7.2, and PnP.PowerShell 2.1.1 (I tried the latest nightly, too). I'm using a managed identity and the principal has full control of sites.
Does this cmdlet only work for users and not groups? Is there a group one that I overlooked?
Add-PnPGroupMember -LoginName GroupName@xxx.onmicrosoft.com -Group 'Site Title Visitors'
Add-PnPGroupMember -LoginName 'Group Name' -Group 'Site Title Visitors'
Add-PnPGroupMember -EmailAddress GroupName@xxx.onmicrosoft.com -Group 'Site Title Visitors'
2023-05-20T19:03:50.645 [Error] ERROR: The specified user i:0#.f|membership|GroupName@xxx.onmicrosoft.com could not be found.Exception :Type : System.Management.Automation.PSInvalidOperationExceptionErrorRecord :Exception :Type : System.Management.Automation.ParentContainsErrorRecordExceptionMessage : The specified user i:0#.f|membership|GroupName@xxx.onmicrosoft.com could not be found.HResult : -2146233087CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordExceptionFullyQualifiedErrorId : InvalidOperationTargetSite :Name : ProcessRecordDeclaringType : PnP.PowerShell.Commands.Base.PnPConnectedCmdletMemberType : MethodModule : PnP.PowerShell.dllMessage : The specified user i:0#.f|membership|GroupName@xxx.onmicrosoft.com could not be found.Source : PnP.PowerShellHResult : -2146233079StackTrace :at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPConnectedCmdlet.cs:line 98at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPSharePointCmdlet.cs:line 120at System.Management.Automation.Cmdlet.DoProcessRecord()at System.Management.Automation.CommandProcessor.ProcessRecord()CategoryInfo : InvalidOperation: (:) [Add-PnPGroupMember], PSInvalidOperationExceptionFullyQualifiedErrorId : InvalidOperation,PnP.PowerShell.Commands.Principals.AddGroupMemberInvocationInfo :MyCommand : Add-PnPGroupMemberScriptLineNumber : 107OffsetInLine : 5HistoryId : 1ScriptName : C:\home\site\wwwroot\createSharePointSite\run.ps1Line : Add-PnPGroupMember -LoginName "GroupName@xxx.onmicrosoft.com" -Group "Site Title Visitors" PositionMessage : At C:\home\site\wwwroot\createSharePointSite\run.ps1:107 char:5+ Add-PnPGroupMember -LoginName "GroupName@xxx.onmicr …+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot : C:\home\site\wwwroot\createSharePointSitePSCommandPath : C:\home\site\wwwroot\createSharePointSite\run.ps1InvocationName : Add-PnPGroupMemberCommandOrigin : InternalScriptStackTrace : at <ScriptBlock>, C:\home\site\wwwroot\createSharePointSite\run.ps1: line 107Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException : Result: ERROR: The specified user i:0#.f|membership|GroupName@xxx.onmicrosoft.com could not be found.Exception :Type : System.Management.Automation.PSInvalidOperationExceptionErrorRecord :Exception :Type : System.Management.Automation.ParentContainsErrorRecordExceptionMessage : The specified user i:0#.f|membership|GroupName@xxx.onmicrosoft.com could not be found.HResult : -2146233087CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordExceptionFullyQualifiedErrorId : InvalidOperationTargetSite :Name : ProcessRecordDeclaringType : PnP.PowerShell.Commands.Base.PnPConnectedCmdletMemberType : MethodModule : PnP.PowerShell.dllMessage : The specified user i:0#.f|membership|GroupName@xxx.onmicrosoft.com could not be found.Source : PnP.PowerShellHResult : -2146233079StackTrace :at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPConnectedCmdlet.cs:line 98at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPSharePointCmdlet.cs:line 120at System.Management.Automation.Cmdlet.DoProcessRecord()at System.Management.Automation.CommandProcessor.ProcessRecord()CategoryInfo : InvalidOperation: (:) [Add-PnPGroupMember], PSInvalidOperationExceptionFullyQualifiedErrorId : InvalidOperation,PnP.PowerShell.Commands.Principals.AddGroupMemberInvocationInfo :MyCommand : Add-PnPGroupMemberScriptLineNumber : 107OffsetInLine : 5HistoryId : 1ScriptName : C:\home\site\wwwroot\createSharePointSite\run.ps1Line : Add-PnPGroupMember -LoginName "GroupName@xxx.onmicrosoft.com" -Group "Site Title Visitors" PositionMessage : At C:\home\site\wwwroot\createSharePointSite\run.ps1:107 char:5+ Add-PnPGroupMember -LoginName "GroupName@xxx.onmicr …+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot : C:\home\site\wwwroot\createSharePointSitePSCommandPath : C:\home\site\wwwroot\createSharePointSite\run.ps1InvocationName : Add-PnPGroupMemberCommandOrigin : InternalScriptStackTrace : at <ScriptBlock>, C:\home\site\wwwroot\createSharePointSite\run.ps1: line 107Exception: The specified user i:0#.f|membership|GroupName@xxx.onmicrosoft.com could not be found.Stack: at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPConnectedCmdlet.cs:line 98at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPSharePointCmdlet.cs:line 120at System.Management.Automation.Cmdlet.DoProcessRecord()at System.Management.Automation.CommandProcessor.ProcessRecord()
Expected behavior
I was expecting it to add the Office 365 group to the visitor group on the SharePoint site.
Actual behavior
See error message above
What is the version of the Cmdlet module you are running?
2.1.1
Which operating system/environment are you running PnP PowerShell on?
Beta Was this translation helpful? Give feedback.
All reactions