In this article, we are going to see how to create a SharePoint user and SharePoint group and add the created user to the SharePoint group using PnP PowerShell. The Client-Side Object Model (CSOM) is used internally for these operations.
Prerequisite
Before you begin utilizing PowerShell to oversee SharePoint Online, ensure that the SharePoint Online Management Shell is installed. You can install the SharePoint Online Management Shell by downloading and running the SharePoint Online Management Shell. You only need to do this once for each computer from which you are running SharePoint Online PowerShell commands.
Connect to Site
Before connecting to the SharePoint site, we need to get credentials by using the Get-Credential cmdlet which creates a credential object for a specified username and password. You can use the credential object in security operations. By default, an authentication dialog box appears to prompt the user like the below example picture
Then connect to SharePoint site using Connect-PnPOnline cmdlet. The required parameters are -Url and -Credential . In -Url Parameter passes the site URL and in -Credential passes the Get-Credential.
The following code snippet helps to connect SharePoint site.
- $credentials= Get-Credential
- $siteurl="https://<tenant-name>. sharepoint.com"
- Connect-PnPOnline -Url $siteurl -Credentials $credentials
Create SharePoint User
The Users can be created by using New-MsolUser command on SharePoint sites. The New-MsolUser cmdlet created a user in a SharePoint site in order to give the user access to services. The required parameters are,
- UserPrincipalName - Specifies email addresses for the user.
- DisplayName - Specifies the display name of the user.
- FirstName - Specifies the first name of the user.
- LastName - Specifies the last name of the user.
The following snippet helps to create SharePoint user on SharePoint site.
- Connect-MsolService -Credential $credentials
- New-MsolUser -UserPrincipalName "ravishankar@<tenant-name>.onmicrosoft.com" -DisplayName "Ravishankar" -FirstName "Ravi" -LastName "Shankar"
Create SharePoint Group
The groups can be created using New-PnPGroup command on SharePoint sites. The required parameters for creating a group is the title. Other parameters can also be added.
- Owner - User Login Name. If not assigned, current user login name is assigned by default.
- Description - Group Description
The following snippet helps to create a new SharePoint group on SharePoint site.
- $newGroup = New-PnPGroup -Title "Hubfly Group" -Owner "ravishankar@<tenant-name>. onmicrosoft.com" -Description "Hubfly Group"

Join the conversation! Your thoughts help the community grow.