Splitting Data from object

Hi

Here is the deal. I have an object with system information. Server Name, SP version, IPaddress, Domain

but the outcome in the IP Address is
IPAddress : 10.222.219.139 fe80::41bd:f635:28c9:dfe8

I would like to split the IPaddress into two lines when I put it on Html.
10.222.219.139
fe80::41bd:f635:28c9:dfe8

here is the code

Function Get-HGSystemInfo{

[CmdletBinding()]

Param(
    [Parameter(Mandatory=$true)]
    [string]$ComputerName ,

    [Parameter()]
    [string]$ErrorLogFilePath = $HGErrorLogPreference
)

Write-Verbose "Gathering system Info" -Verbose
$os = Get-WmiObject -class Win32_Operatingsystem -ComputerName $ComputerName -Credential $cred
$cs = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $ComputerName -Credential $cred
$network = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $ComputerName -Credential $cred|
                where 'IPEnabled' -EQ "True"

$props = @{ 'ComputerName' = $ComputerName;
            'OSversion' = $os.caption;
            'SPversion' = $os.CSDVersion;
            'Manufacturer' = $cs.Manufacturer;
            'Model' = $cs.Model;
            'TotalPhysicalMemory' = $cs.TotalPhysicalMemory / 1gb -as [int];
            'Domain' = $cs.Domain;
            'IPAddress' = $network.IPAddress -as [string]

}

$osObj = New-Object -TypeName PSObject -Property $props
Write-Verbose "Done Gathering system Info"
Write-Output $osObj 

}

$os_html = Get-HGSystemInfo -ComputerName $servername |ConvertTo-EnhancedHTMLFragment -DivCssID ‘OS’ -TableCssClass ‘PaintRow’ -As list -PreContent “System Info” `
-Properties ComputerName, OSversion, SPversion,TotalPhysicalMemory,Manufacturer,Model,IPAddress ,Domain |Out-String

$os_html

$Title = “Windows SIC Verification”
$head = @"
Windows SIC Verification
$servername
This report was run: $(get-date)
"@

ConvertTo-Html -Title $Title -Head $head -PreContent $os_html |out-file $htmlReport

System Info

Computername : LQVWA93A0009.ent.wfb.bank.qa
OSversion : Microsoft Windows Server 2012 R2 Standard
SPversion :
TotalPhysicalMemory : 8
Manufacturer : VMware, Inc.
Model : VMware Virtual Platform
IPAddress : 10.222.219.139 fe80::41bd:f635:28c9:dfe8
Domain : ent.wfb.bank.qa

How can I do it?

Try this

$props.IPAddress.split(" ")

Or this if you want only the ip

‘IPAddress’ = $network.IPAddress.split(" “)[0] -as [string]
‘IPAddress2’ = $network.IPAddress.split(” ")[1] -as [string]

It is already “split” because the IPAddress property is an array of strings. You are actually joining it together when you use -as [string]

$ip = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled = $True")[1].IpAddress
$ip
write-host "--------------------"
$ip -as [string]

Results in:

172.16.96.55
fe80::c963:948b:4fb8:67d0
--------------------
172.16.96.55 fe80::c963:948b:4fb8:67d0

You can see the first results in the different array elements being listed while the second, with the -as [string] concatenates the array elements into a space separated string.

Man I feel like an idiot. I think I will just keep my mouth shut for now on and just wait for Curtis to answer :smiley:

@mark-hammonds Simple oversight, your answer was not wrong, and it does do what was asked. Don’t be so down on yourself. You provide good feedback and provoke thought. Keep it up.

Thanks bud. My mind has been all over the place since that last discussion we have had I have been reading Beginning of Regular Expression by Andrew Watt. I had no idea the power of regex. you guys definitely keep me on my toes. :smiley: