Author Posts

November 30, 2015 at 4:42 pm


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 :
OSversion : Microsoft Windows Server 2012 R2 Standard
SPversion :
TotalPhysicalMemory : 8
Manufacturer : VMware, Inc.
Model : VMware Virtual Platform
IPAddress : fe80::41bd:f635:28c9:dfe8
Domain :

How can I do it?

November 30, 2015 at 6:50 pm

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]

November 30, 2015 at 9:08 pm

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.

December 1, 2015 at 3:59 am

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 😀

December 1, 2015 at 8:55 am

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

December 1, 2015 at 9:00 am

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