Splitting Data from object

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Mark Hammonds Mark Hammonds 10 months, 4 weeks ago.

  • Author
  • #32424
    Profile photo of Helder Guzman
    Helder Guzman


    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 : fe80::41bd:f635:28c9:dfe8

    I would like to split the IPaddress into two lines when I put it on Html.

    here is the code

    Function Get-HGSystemInfo{


    [string]$ComputerName ,

    [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


    $Title = "Windows SIC Verification"
    $head = @"
    Windows SIC Verification
    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 : fe80::41bd:f635:28c9:dfe8
    Domain : ent.wfb.bank.qa

    How can I do it?

  • #32425
    Profile photo of Mark Hammonds
    Mark Hammonds

    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]

  • #32428
    Profile photo of Curtis Smith
    Curtis Smith

    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
    write-host "--------------------"
    $ip -as [string]

    Results in:
    -------------------- 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.

  • #32435
    Profile photo of Mark Hammonds
    Mark Hammonds

    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 😀

  • #32459
    Profile photo of Curtis Smith
    Curtis Smith

    @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.

  • #32460
    Profile photo of Mark Hammonds
    Mark Hammonds

    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. 😀

You must be logged in to reply to this topic.