Remove Everyone Permissions and add Authenticate Users permissions to Net Share folders

Lingareddy Chandrakanth Reddy 1 Reputation point
2021-11-16T13:36:37.783+00:00

I got a script from someone to remove the Everyone permission and add the Authenticated Users permissions for the Net share.

But my script is removing it and adding the Authenticated Users, but it is only performing the action for the Root folders, not for the subfolder inside the root folder and I need to get that permission as an Inherited form parent.

I want to remove the Everyone permission from the root folder and the subfolders add the Authenticated Users to the root folder and to the Subfolders need to be added.
And I just want to know like my script is excluding the shares which for ('Remote Admin' ,"Default share' , 'Remote IPC' , 'Printer Drivers'")

It would be great if someone can please help me achieve this...

$ScriptBlock = {
     "Executing on {0}" -f $env:COMPUTERNAME
     $ExclusionList = 'ADMIN\$','IPC\$' -join '|'
     $Shares = Get-SmbShare  | Where-Object -Property Name -notmatch $ExclusionList | Where-Object -Property Path -notmatch '^\w:\\$' 
     "Analyzing these shares...."
     $Shares
     foreach ($Share in $Shares) {    
         $Everyone = Get-SmbShareAccess $Share.Name | Where-Object -Property AccountName -eq Everyone
         if ($Everyone) {  
             Revoke-SmbShareAccess $Share.Name -AccountName 'Everyone' -Force
             Grant-SmbShareAccess $Share.Name -AccountName 'Authenticated Users' -AccessRight FullControl -Force
             "Share {0} has been updated." -f $Share.Name 
         }
     }
     "Complete"
 }


  $ComputerList = Get-Content "C:\users\a-lchandrakanthredd\Desktop\Test\Servers.txt"

  Invoke-Command -ComputerName $ComputerList -ScriptBlock $ScriptBlock
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2021-11-16T16:49:30.697+00:00

    I have written a script to remove the Everyone permission and add the Authenticated Users permissions for the Net share.

    No you did not. I wrote the key elements to that script.

    This question is a duplicate of your original post.

    https://learn.microsoft.com/en-us/answers/questions/624776/managing-windows-file-shares-with-powershell.html

    If you want forum users to help you, don't claim that code that we wrote for you is your own.

    1 person found this answer 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.