troubleshooting Question

Need output in powershell ( Vertical format)

Avatar of Suresh Kumar
Suresh Kumar asked on
HTMLPowershell* ip
2 Comments1 Solution447 ViewsLast Modified:

param (


[string[]$ComputerName = $env:computername


begin {}

process {

foreach ($Computer in $ComputerName) {

if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {

try {

$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer -EA Stop | ? {$_.IPEnabled}

} catch {

Write-Warning "Error occurred while querying $computer."



foreach ($Network in $Networks) {

$IPAddress = $Network.IpAddress[0]

$SubnetMask = $Network.IPSubnet[0]

$DefaultGateway = $Network.DefaultIPGateway

$DNSServers = $Network.DNSServerSearchOrder


$IP4 = $Network.IPAddress | where{$_ -match "\d+\.\d+\.\d+\.\d+"}

$IP6 = $Network.IPAddress | where{$_ -match "\:\:"}

$WINSPrimary = $Network.WINSPrimaryServer

$WINSSecondary = $Network.WINSSecondaryServer

$IP4Subnet = $Network.IPSubnet | where{$_ -match "\d+\.\d+\.\d+\.\d+"}

$IsDHCPEnabled = $false

If($network.DHCPEnabled) {

$IsDHCPEnabled = $true


$MACAddress = $Network.MACAddress

$OutputObj = New-Object -Type PSObject

$OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()

$OutputObj | Add-Member -MemberType NoteProperty -Name IPAddress -Value $IPAddress

$OutputObj | Add-Member -MemberType NoteProperty -Name SubnetMask -Value $SubnetMask

$OutputObj | Add-Member -MemberType NoteProperty -Name Gateway -Value $DefaultGateway.ToUpper()

$OutputObj | Add-Member -MemberType NoteProperty -Name IsDHCPEnabled -Value $IsDHCPEnabled

foreach($try in $DNSServers)


$DNScount= $DNScount + 1

$Name="DNSServer" + $DNScount.ToString()

$OutputObj | Add-Member -MemberType NoteProperty -Name $Name -Value $try


$OutputObj | Add-Member -MemberType NoteProperty -Name DNSServers -Value $DNSServers.ToLower()

$OutputObj | Add-Member -MemberType NoteProperty -Name MACAddress -Value $MACAddress

$OutputObj | Add-Member -MemberType NoteProperty -Name IP4 -Value $IP4

$OutputObj | Add-Member -MemberType NoteProperty -Name IP6 -Value $IP6

$OutputObj | Add-Member -MemberType NoteProperty -Name WINSPrimary -Value $WINSPrimary

$OutputObj | Add-Member -MemberType NoteProperty -Name WINSSecondary -Value $WINSSecondary

$OutputObj | Add-Member -MemberType NoteProperty -Name IP4Subnet -Value $IP4Subnet

$a = "<style>"

$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"

$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"

$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"

$a = $a + "</style>"

$OutputObj | ConvertTo-Html -head $a -body "<H2>IP ADDRESS</H2>" | Out-File -FilePath C:\tmp\IP.txt

#cat C:\tmp\IP.txt

#Invoke-Expression C:\tmp\IP.txt

Get-Content 'C:\tmp\IP.txt' | Foreach-Object {$_ -replace '^<html.*$', ("<html>")} | Set-Content 'C:\tmp\IP1.txt'

cat C:\tmp\IP1.txt





end {}

When i run the above script the output comes horizontal format

Computer Name  IP address Subnetmask gateway

Need the ouput in Vertical format
Computer Name
IP adress              
can you help me wih this?
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros