I have written a script 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.
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
Thanks In Advance.