I have been given a task of removing “everyone” from our network shares. I have the powershell script for this as it seemed to be pretty straightforward. However, when I implemented this as a Configuration Baseline a problem was found. There are systems that were unable to complete their daily tasks when the “everyone” permission was removed. We monitored the situation and I have now been given a list of IP addresses that should be excluded from the remove “everyone” CB. Problem is, I don’t know how to include a list of excluded IP´s in my powershell script. Here is what I have so far but I would like someone to tell me if I am on the correct path.
$ExcludedIPs = "10.145.0.0/16","10.146.0.0/16"
$IPAddress = [System.Net.Dns]::GetHostAddresses($env:COMPUTERNAME) | Select-Object -ExpandProperty IPAddressToString
$Shares = (Get-SmbShare |Where-Object {($_.Name -notmatch ".+\$") -and ($IPAddress -notin $ExcludedIPS)} | Get-SmbShareAccess | Where-Object {$_.AccountName -eq "Everyone"})
IF ($Shares -ne $null)
{Get-SmbShare | Where-Object {($_.Name -notmatch ".+\$") -and ($IPAddress -notin $ExcludedIPS)} | Get-SmbShareAccess | Where-Object {$_.AccountName -eq "Everyone"} | ForEach-Object {Revoke-SmbShareAccess -name $_.name -AccountName $_.AccountName -Force}}
ELSE
{}