I have the following piece of code to break role inheritance in specific folder and apply another role
$folder= $web.GetFolder($folderURL)
$folder.Item.BreakRoleInheritance("true")
Success
it works fine when I set cleaned url
$folderURL=http://thalabapp01:10574/sites/SiteCollection1/Test3/Test4
Failure It failed in both:
I copy full url from browser for the same folder Test4 and set it to $folderURL $folderURL=http://thalabapp01:10574/sites/SiteCollection1/_layouts/15/start.aspx#/DocummentLibrary1/Forms/AllItems.aspx?RootFolder=%2Fsites%2FSiteCollection1%2FDocummentLibrary1%2FTest3%2FTest4&FolderCTID=0x012000CB838094FA7E5547AE67B658B37A595B&View=%7B80AA6D44%2DD5AD%2D496B%2D87C7%2D660CEB513A92%7D
Used folder in shared documents http://thalabapp01:10574/sites/SiteCollection1/Documents/Test2
The error is : You cannot call a method on a null-valued expression. At D:\GrantPermissions\GrantPermission.ps1:9 char:4 + $folder.Item.BreakRoleInheritance("true") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
Please advice !