Author Posts

October 29, 2015 at 1:37 pm

I need some help on reordering my string value for ReverseDNS.

Currently String:
I want it to be:

I tried use regex to switch the string in reverse but it does all the values:

October 29, 2015 at 1:51 pm

split and then reassemble in reverse

$IPOctects = "" -split "\."
$IP = "$($IPOctects[3]).$($IPOctects[2]).$($IPOctects[1]).$($IPOctects[0])"

October 29, 2015 at 1:56 pm

Thanks Curtis, that's exactly what I was trying to accomplish

October 29, 2015 at 1:58 pm

Or split into an array, reverse the array, and join string again

PS C:\> $String = ''
PS C:\> $String

PS C:\> $Array = $String.Split('.')
PS C:\> [array]::Reverse($Array)
PS C:\> $Reversed = $Array -join '.'

PS C:\> $Reversed

October 29, 2015 at 2:01 pm


$IP = "".split(".")
$IP -join "."

October 29, 2015 at 2:02 pm

ah, bet me to the other option Christian 😀

October 29, 2015 at 2:19 pm

I was actually going to suggest the reverse method also. However I got stuck for a couple of minutes due to the fact that the static reverse method does not return anything (void) and the signature does not suggest that is takes a [ref] variable ( static void Reverse(array array)). As it is a void, it should not return anything, however how does that work without [ref]?

October 29, 2015 at 2:21 pm

Is there a way to have the input as a variable? Instead of a static entry of, the variable may contain more than one entry.

$IPs = '',''

October 29, 2015 at 2:44 pm

but of course there is. Here is an advanced function that supports pipeline input as well: