# Exclude a list of IP ranges

**URL:** <https://forums.powershell.org/t/exclude-a-list-of-ip-ranges/21824>\
**Category:** PowerShell Help\
**Created:** [March 6, 2023, 2:15pm UTC](https://forums.powershell.org/t/exclude-a-list-of-ip-ranges/21824 "2023-03-06T14:15:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![idontknow](https://avatars.discourse-cdn.com/v4/letter/i/d2c977/32.png) [@idontknow](https://forums.powershell.org/u/idontknow)\
**Post date:** [March 6, 2023, 2:15pm UTC](https://forums.powershell.org/t/exclude-a-list-of-ip-ranges/21824/1 "2023-03-06T14:15:38Z")

</div>

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.

```auto
$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
 {}

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 6, 2023, 2:50pm UTC](https://forums.powershell.org/t/exclude-a-list-of-ip-ranges/21824/2 "2023-03-06T14:50:25Z")

</div>

> [@idontknow](#):
>
> I have been given a task of removing “everyone” from our network shares.

It is actually common best practice to have “`everyone`” on the shares permissions and manage the access rights on the file system side - not the share side. 🤷🏽‍♂️

> [@idontknow](#):
>
> I have now been given a list of IP addresses that should be excluded from the remove “everyone” CB.

?? I didn’t get this. Shares actually do not have any IP address setting. 🤔

> [@idontknow](#):
>
> `($IPAddress -notin $ExcludedIPS)`

That will probably not work as you might think it does. For that to work `$IPAddress` would need to be an exact member of the array represented by `$ExcludedIPS`. So for example `blue` would be found in `(blue,red,green)` but not in `(Color blue, color red, color green)`.

---

<div class="post-metadata">

**Author:** ![Matt](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Matt](https://forums.powershell.org/u/Matt)\
**Post date:** [March 7, 2023, 2:49am UTC](https://forums.powershell.org/t/exclude-a-list-of-ip-ranges/21824/3 "2023-03-07T02:49:25Z")

</div>

I agree with Olaf based on what you share. Not sure why you want to remove “everyone” from the share permissions. NTFS permissions actually control if you see, read, write, delete etc. Even with “everyone” left in the share permission, if your NTFS permissions are set correctly, “everyone” will not have access to “everything”.

There is no way to say remove “everyone” except from this IP. Doesn’t work that way.

Typically, when you have to remove “everyone”, you replace “everyone” with a new group that has a naming convention that makes it clear it is for the share and holds the share permissions. To simplify, you also then create a group to hold the NTFS permission and then nest that group into the “share group”.

This prevents you from having to remember to add user and service accounts to two groups, you add them to the NTFS group only. But you could keep the groups separate and just remember to add users to the two group. All about the politics in your organization and management decisions around security, regardless of if they make sense or not.

Permissions can be a real pain to wrap your head around, but once you do, you can do some pretty cool stuff. When I managed our file server, I was told to reduce the number of shares. I started creating a single share for common projects. One such was ITAR governed project. which means users from project A CANNOT see data for project B…EVER.

I still only used one share, but based on NTFS permissions people would only ever see their project. even though there were multiple folders below the shared one, if you were not a member of the project, you didn’t even see the folders you didn’t have access too. So, it wasn’t a case of they could see the “root” folders but not access, they couldn’t even see them because of the NTFS permissions.

You may not be able to change your management’s directive, but it is not about the share permissions, rather it is ALL about the NTFS permissions if you want to be secure.

---

<div class="post-metadata">

**Author:** ![idontknow](https://avatars.discourse-cdn.com/v4/letter/i/d2c977/32.png) [@idontknow](https://forums.powershell.org/u/idontknow)\
**Post date:** [March 7, 2023, 7:49am UTC](https://forums.powershell.org/t/exclude-a-list-of-ip-ranges/21824/4 "2023-03-07T07:49:38Z")

</div>

Thanks Olaf, the idea is that the Configuration Baseline would only be deployed to computers in a certain IP range. I agree that removing everyone isn’t the best solution. I will chat with management again.

---

<div class="post-metadata">

**Author:** ![idontknow](https://avatars.discourse-cdn.com/v4/letter/i/d2c977/32.png) [@idontknow](https://forums.powershell.org/u/idontknow)\
**Post date:** [March 7, 2023, 7:50am UTC](https://forums.powershell.org/t/exclude-a-list-of-ip-ranges/21824/5 "2023-03-07T07:50:17Z")

</div>

Yes, you make very valid points. I will try to address this issue with management again.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:15pm UTC](https://forums.powershell.org/t/exclude-a-list-of-ip-ranges/21824/6 "2024-05-16T20:15:05Z")

</div>

Closed on May 16, 2024, 8:15pm UTC


