About powershell scripts (Sharepoint)

jennyKim 240 Reputation points
2023-06-14T02:52:06.8833333+00:00

I have run following command for user to grant permission

#Parameters

$SiteURL = "https://sara56.sharepoint.com/"

$UserAccount = "******@Sara56.onmicrosoft.com"

$PermissionLevel = "Members"

#Connect to PnP Online

Connect-PnPOnline -Url https://sara56.sharepoint.com/ -Interactive

#grant access to sharepoint online site with powershell

Set-PnPWebPermission -User $UserAccount -AddRole $PermissionLevel

But when ever I run this command following error has been occured

Error: Exception calling "ExecuteQuery" with "0" arguments: "Permission level not found."

I tried with Edit,Owner,Contribute permission but no luck still the same error will occur

Can anyone please tell me what am i missing

Did i mistake the permission level?

Microsoft 365 and Office | SharePoint Server | For business
Microsoft 365 and Office | Install, redeem, activate | For business | Windows
Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft 365 and Office | SharePoint Server | Development
0 comments No comments
{count} votes

Accepted answer
  1. Ling Zhou_MSFT 23,620 Reputation points Microsoft External Staff
    2023-06-14T07:13:41.3766667+00:00

    Hi @jennyKim

    Thank you for posting in the community.

    I checked your PowerShell scripts and found no problems.

    Here are the PowerShell scripts I tested:

    #Parameters
    $SiteURL = "SiteURL"
    $UserAccount = "******@XXXXX.onmicrosoft.com"
    $PermissionLevel = "Contribute"
     
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL 
     
    #grant access to sharepoint online site with powershell
    Set-PnPWebPermission -User $UserAccount -AddRole $PermissionLevel
    

    Here is the result of my test:

    enter image description here Since we can't reproduce your situation, we need to narrow down the problem and try some things.

    1, Please go to Site Settings->site permissions ->permissions levels. Make sure the permission level in your command exists in your site.

    User's image

    2, If the problem persists, try a different computer. Check if the problem still exists.


    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.


0 additional answers

Sort by: Most helpful

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.