Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Removing the last octet of an IP address

$
0
0

Hi,

To remove the last octet of an IP address I put together the following:

$array = New-Object System.Collections.ArrayList
$ipaddress.Split(".") | ForEach-Object {$array.Add($_)} | Out-Null
$array.Remove($array[3])
$ipaddress = ($array -join ".") + "."

However, I`m sure there are other, more effective ways to do this, i.e. using regex to "remove the third group of digits after the 3rd dot".

Any suggestions around this?

I.e. 192.168.0.10 should be 192.168.0. 


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>