We help IT Professionals succeed at work.

Need output in powershell ( Vertical format)

Suresh Kumar
Suresh Kumar asked
Last Modified: 2017-03-17

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?
Watch Question

Most Valuable Expert 2019
Most Valuable Expert 2018
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)



Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions