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