Break permission Inheritance in sharepoint subsite

HI All,

I want to break inheritance permission of sub site and then add 3 groups eg. Test owner, Test member and Test visitor and add one user in each of the 3 groups using powershell script

Can some one help me?

@Shubham Welcome to forums.

Yes such things should be possible. But it would be better if you can make the question lil more clear.

What is the site you are referring here ?
Do you have some sort of code already you tried to do this ?

Hi @kvprasoon ,

I have a sharepoint subsite, and yes I tried " $web.BreakRoleInheritance($true, $false)"

but it is throwing error

Okay. Then it will be better to share the script/full code if possible. It will help anyone trying here to help you.

Hi @kvprasoon

Connect-PnPOnline -Url "$web" -Credentials (Get-Credential)
   $web.BreakRoleInheritance($True, $False)

only these lines I have written, but its not working,

error:You cannot call a method on a null-valued expression.
At line:1 char:2
+  $web.BreakRoleInheritance($True, $False)
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

$web needs to be defined…

$web is a variable, What is inside that variable ?
When $web.BreakRoleInheritance($True, $False) is used, its assumed that $web is an object which has a method named BreakRoleInheritance().

So if $web is not defined and is not a proper object this wont work.

Something from below link might help you.

SharePoint Online: PowerShell to Break Folder Permission Inheritance - SharePoint Diary

Please don’t jump into it a execute, try to understand what each line is doing. Take your time to understand otherwise it will take more time to sort it out.

@krzydoug @kvprasoon
$web has url of the site

Thats not how it works. Please read that article. It will help you.

Take some time understand Methods and Properties of an object. Otherwise it will be difficult to understand and getting help. Those are some basics every PowerShell user should understand.

Discovering objects, properties, and methods - PowerShell | Microsoft Docs