JRN JRN - 2 months ago 10x
PowerShell Question

Unable to split an IP address

I am trying to collect an IP Address and then split that IP address however I keep getting an error message.

$Hostname = hostname
$IPAddress = Test-Connection $Hostname -Count 1 | Select IPV4ADDRESS | Format-Table -HideTableHeaders
$IPAddress2 = $IPAddress.Split('.')

Error Message: Method invocation failed because

[Microsoft.PowerShell.Commands.Internal.Format.FormatStartData] does
not contain a method named 'Split'.


Try that

(Test-Connection $hostname -Count 1).IPV4Address.GetAddressBytes() | 
    % { $_.ToString() }  

The output of the Format-XXX cmdlets is not intended being used as strings etc. as this are formatting commands for the console