Hello, I’m trying to remove the ‘everyone’ group from any shares. I found some code and modified as follows:
foreach($share in (Get-WmiObject win32_share |?{$_.name -notmatch "C\$|ADMIN\$|IPC\$|NETLOGON SYSVOL"} | select -expandProperty Name))
{
#get settings
$set = get-wmiobject -Class Win32_LogicalshareSecuritySetting -filter "Name='$share'"
#filter Everyone out
$revised = $set.GetSecurityDescriptor().Descriptor.Dacl | Where {$_.trustee.name -ne 'Everyone'}
#set the new ACL
$descriptor = $set.GetSecurityDescriptor().descriptor
$descriptor.dacl = $revised
$set.SetSecurityDescriptor($descriptor)
}
This works great if the shares have multiple DACLs, but if it only has “everyone” in the share, then $revised is null and it wont change the ACL…I figure i need something like
foreach($share in (Get-WmiObject win32_share |?{$_.name -notmatch "C\$|ADMIN\$|IPC\$|NETLOGON SYSVOL"} | select -expandProperty Name))
{
#get settings
$set = get-wmiobject -Class Win32_LogicalshareSecuritySetting -filter "Name='$share'"
#filter Everyone out
$revised = $set.GetSecurityDescriptor().Descriptor.Dacl | Where {$_.trustee.name -ne 'Everyone'}
if($revised -eq $null)
{
#remove everyone from share permission
}
else
{
#set the new ACL
$descriptor = $set.GetSecurityDescriptor().descriptor
$descriptor.dacl = $revised
$set.SetSecurityDescriptor($descriptor)
}
}
I’m just not sure how to remove ‘everyone’ if $revised is null…any help would be greatly appreciated