{"id":6212,"date":"2020-08-07T13:16:22","date_gmt":"2020-08-07T13:16:22","guid":{"rendered":"https:\/\/www.softreetechnology.com\/?p=6212"},"modified":"2020-08-07T13:16:22","modified_gmt":"2020-08-07T13:16:22","slug":"sharepoint-permission-tasks-using-pnp-powershell","status":"publish","type":"post","link":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/sharepoint-permission-tasks-using-pnp-powershell\/","title":{"rendered":"SharePoint Permission Tasks Using PnP PowerShell"},"content":{"rendered":"\n<p>In this blog, we are going to discuss about the SharePoint permission in\ndifferent scenarios like how to assign &amp; remove permission to a user, how\nto assign unique permission. Also, we will retrieve the users and the\ncorresponding role associated with them. <\/p>\n\n\n\n<p>SharePoint Permission is used for assigning different types of\nroles\/permission to different users. A user can perform activity according to\nthe permission or role which is assigned to the user. There are Different types\nof permissions\/roles available in SharePoint.<\/p>\n\n\n\n<p>Here, we will use PnP Online to perform the permission tasks. Please\nfollow the below Code snippet and the steps given to perform the permission\ntasks.<\/p>\n\n\n\n<p><strong>Step-1: &#8211; <\/strong>Let us open the windows PowerShell ISE as administrator, and then run the code in PowerShell. <\/p>\n\n\n\n<p><strong>Step-2: &#8211; <\/strong>Enter the user Credentials.<\/p>\n\n\n\n<p><strong>Step-3: &#8211;<\/strong> Get Site collection, Group &amp; User.<\/p>\n\n\n\n<p><strong>Step-4: &#8211; <\/strong>Get the user associated with site and their respective role.<\/p>\n\n\n\n<p><strong>Step-5: &#8211;<\/strong>Then assigned permission to a user &amp;\nalso mentioned how to remove the permission.<\/p>\n\n\n\n<p><strong>Step-6: &#8211; <\/strong>Also assigned unique permissions for\nlist, list items &amp; subsite. For subsite we have to assign the unique\npermission while creating the subsite by breaking the root site inheritance.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Provide URL of the Site \n$sUrl = \"https:\/\/Contoso.sharepoint.com\/sites\/SiteName\"\ntry\n{\n#pass valid credentials \nConnect-PnPOnline -Url $sUrl -Credentials (Get-Credential)\n$siteColl = Get-PnPTenantSite\n\nGet-PnPGroup \n\nGet-PnPUser \n\n#To get the user and their corresponding role\n$web = Get-PnPWeb -Includes RoleAssignments\nforeach($ra in $web.RoleAssignments)\n{\n$member = $ra.Member\n $loginName = get-pnpproperty -ClientObject $member -Property    LoginName\n$rolebindings = get-pnpproperty -ClientObject $ra -Property RoleDefinitionBindings\nwrite-host \"$($loginName) - $($rolebindings.Name)\"\nwrite-host  \n}\n#To assign a role\/Permission to the user in site\nSet-PnPWebPermission -User 'test@user.onmicrosoft.com' -AddRole 'contribute'\n#To remove permission of an user\nSet-PnPWebPermission -User 'test@user.onmicrosoft.com' -RemoveRole 'Read'\n# Add unique permission to list, first we have remove unique permissions if any\nSet-PnPListPermission -Identity 'ctlist' -User 'test@user.onmicrosoft.com' -AddRole 'Contribute'\n# Add unique permission to list items\nSet-PnPListItemPermission -List 'MULlist' -Identity 3 -User 'test@user.onmicrosoft.com' -AddRole 'Edit'\n\nwrite-host \"Successful\"\n\n$mysubsite = New-PnPWeb -Title \"Subsite\" -Url  Subsiteurl \n-Description \"A subsite\" -Locale 1033 -Template \"STS#0\" -BreakInheritance \n\nAdd-PnPTenantSequenceSubSite -Site $siteColl -SubSite $mysubsite\n\n\nWrite-host \"Site '$SiteTitle' Created Successfully!\" \n}\ncatch\n{\n write-host -f Red \"Error:\" $_.Exception.Message\n} \n<\/code><\/pre>\n\n\n\n<p><strong><em><span style=\"text-decoration: underline;\">Conclusion: <\/span><\/em><\/strong> Hence we have concluded after performing the above operation that we can set\/recognize the permissions quite easily regarding the requirement of an organization. This will lead to the improvement of the security level and as well as for better performance. <\/p>\n\n\n\n<p><strong><em><span style=\"text-decoration: underline;\">Keywords<\/span><\/em><\/strong>:<br> \u2022 How to set SharePoint Permission to a user using PnP PowerShell.<br> \u2022 How to set Unique Permission for list\/library using PnP PowerShell.<br> \u2022 How to set Unique Permission to subsite using PnP PowerShell.<br> \u2022 SharePoint permission tasks using PnP PowerShell.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we are going to discuss about the SharePoint permission in different scenarios like how to assign &amp; remove permission to a user, how to assign unique permission. Also, we will retrieve the users and the corresponding role associated with them. SharePoint Permission is used for assigning different types of roles\/permission to different users. A user can perform [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[298],"tags":[],"class_list":["post-6212","post","type-post","status-publish","format-standard","hentry","category-pnp-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SharePoint Permission Tasks Using PnP PowerShell - Softree Technology<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/sharepoint-permission-tasks-using-pnp-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SharePoint Permission Tasks Using PnP PowerShell - Softree Technology\" \/>\n<meta property=\"og:description\" content=\"In this blog, we are going to discuss about the SharePoint permission in different scenarios like how to assign &amp; remove permission to a user, how to assign unique permission. Also, we will retrieve the users and the corresponding role associated with them. SharePoint Permission is used for assigning different types of roles\/permission to different users. A user can perform [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/sharepoint-permission-tasks-using-pnp-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"Softree Technology\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-07T13:16:22+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SharePoint Permission Tasks Using PnP PowerShell - Softree Technology","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/sharepoint-permission-tasks-using-pnp-powershell\/","og_locale":"en_US","og_type":"article","og_title":"SharePoint Permission Tasks Using PnP PowerShell - Softree Technology","og_description":"In this blog, we are going to discuss about the SharePoint permission in different scenarios like how to assign &amp; remove permission to a user, how to assign unique permission. Also, we will retrieve the users and the corresponding role associated with them. SharePoint Permission is used for assigning different types of roles\/permission to different users. A user can perform [&hellip;]","og_url":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/sharepoint-permission-tasks-using-pnp-powershell\/","og_site_name":"Softree Technology","article_published_time":"2020-08-07T13:16:22+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/sharepoint-permission-tasks-using-pnp-powershell\/#article","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/sharepoint-permission-tasks-using-pnp-powershell\/"},"author":{"name":"admin","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b"},"headline":"SharePoint Permission Tasks Using PnP PowerShell","datePublished":"2020-08-07T13:16:22+00:00","mainEntityOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/sharepoint-permission-tasks-using-pnp-powershell\/"},"wordCount":287,"commentCount":0,"publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"articleSection":["PnP PowerShell"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/softreetechnology.com\/blog\/pnp-powershell\/sharepoint-permission-tasks-using-pnp-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/sharepoint-permission-tasks-using-pnp-powershell\/","url":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/sharepoint-permission-tasks-using-pnp-powershell\/","name":"SharePoint Permission Tasks Using PnP PowerShell - Softree Technology","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/#website"},"datePublished":"2020-08-07T13:16:22+00:00","breadcrumb":{"@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/sharepoint-permission-tasks-using-pnp-powershell\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/softreetechnology.com\/blog\/pnp-powershell\/sharepoint-permission-tasks-using-pnp-powershell\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/sharepoint-permission-tasks-using-pnp-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softreetechnology.com\/blog\/"},{"@type":"ListItem","position":2,"name":"SharePoint Permission Tasks Using PnP PowerShell"}]},{"@type":"WebSite","@id":"https:\/\/softreetechnology.com\/blog\/#website","url":"https:\/\/softreetechnology.com\/blog\/","name":"Softree Technology","description":"Celebrating 10+ Years in SharePoint Consulting !","publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/softreetechnology.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/softreetechnology.com\/blog\/#organization","name":"Softree Technology","url":"https:\/\/softreetechnology.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","contentUrl":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","width":844,"height":230,"caption":"Softree Technology"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b","name":"admin","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/softreeconsulting.com"],"url":"https:\/\/softreetechnology.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=6212"}],"version-history":[{"count":0,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6212\/revisions"}],"wp:attachment":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=6212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=6212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=6212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}