what is the equivalent code for Microsoft.SharePoint.SPFieldUserValueCollection in PnP Power shell

john john 1,021 Reputation points
2022-12-21T10:15:23.287+00:00

I have the following onpremises power shell:-

$HRCollabs = $null  
[Microsoft.SharePoint.SPFieldUserValueCollection]$HRCollabs = New-Object Microsoft.SharePoint.SPFieldUserValueCollection  
$HRuserValue = New-Object Microsoft.SharePoint.SPFieldUserValue($spSourceWeb, $HRCollabUser.Id, $HRCollabUser.LoginName)              
$StepHRC = "`t" + "Adding HR Collaborator's user to HR collab collection: $HRCollabUser.Id $HRCollabUser.LoginName"  
$HRCollabs.Add($HRuserValue)  

and i need to change it to PnP Powershell. can anyone advice if this is possible?

Thanks

Microsoft 365 and Office | SharePoint | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,481 Reputation points Microsoft External Staff
    2022-12-22T01:50:10.287+00:00

    Hi @john john
    You can use following pnp powershell to add users to groups

    $UserIDs = "******@crescent.com","******@crescent.com"  
    Connect-PnPOnline -Url https://crescent.sharepoint.com/sites/test -Interactive  
       
    #Get the Associcated Owners group of the site  
    $Web = Get-PnPWeb  
    $Group = Get-PnPGroup -AssociatedOwnerGroup  
       
    #sharepoint online add user to group powershell  
    ForEach($User in $UserIDs)  
    {  
        Add-PnPGroupMember -LoginName $User -Identity $Group  
        Write-host -f Green "`tAdded $User to $($Group.Title)"  
    }  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.