Need output in powershell ( Vertical format)

[cmdletbinding()]

param (

[parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]

[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."

Continue

}

foreach ($Network in $Networks) {

$IPAddress = $Network.IpAddress[0]

$SubnetMask = $Network.IPSubnet[0]

$DefaultGateway = $Network.DefaultIPGateway

$DNSServers = $Network.DNSServerSearchOrder

$DNScount=0

$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
                                 172.24.22.180  255.255.255.128  172.24.22131

Need the ouput in Vertical format
Computer Name
IP adress              
SubnetMask    
gateway            
 
can you help me wih this?
Suresh KumarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
ConvertTo-Html will by default create a table, with one column for each property. You can use the "-As List" argument to create a list, similar to Format-List.
This is somewhat changed; even though your arguments supported a computer list, the script would just overwrite the same file. This combines the output of all machines entered.
Note: when you post code, please put it into [code][]/code] tags (see toolbar above the input field). makes it a lot easier to handle it.
[cmdletbinding()]
Param (
	[parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
	[string[]]$ComputerName = $env:computername
)
Begin {
	$Head = @'
		<style>
		TABLE	{border-width:1px; border-style:solid; border-color:black; border-collapse:collapse;}
		TH		{border-width:1px; padding:0px; border-style:solid; border-color:black;}
		TD		{border-width:1px; padding:0px; border-style:solid; border-color:black;}
		</style>
'@
	$ComputerList = @()
}

Process {
	Foreach ($Computer in $ComputerName) {
		$ComputerList += $Computer
	}
}

End {
	$CombinedOutput = Foreach ($Computer in $ComputerList) {
		If (Test-Connection -ComputerName $Computer -Count 1 -ea 0) {
			Try {
				$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "IPEnabled='True'" -ComputerName $Computer -EA Stop
			} Catch {
				Write-Warning "Error occurred while querying $computer."
				Continue
			}
			Foreach ($Network in $Networks) {
				$IPAddress = $Network.IpAddress[0]
				$SubnetMask = $Network.IPSubnet[0]
				$DefaultGateway = $Network.DefaultIPGateway
				$DNSServers = $Network.DNSServerSearchOrder
				$IP4 = $Network.IPAddress | Where-Object {$_ -match "\d+\.\d+\.\d+\.\d+"}
				$IP6 = $Network.IPAddress | Where-Object {$_ -match "\:\:"}
				$WINSPrimary = $Network.WINSPrimaryServer
				$WINSSecondary = $Network.WINSSecondaryServer
				$IP4Subnet = $Network.IPSubnet | Where-Object {$_ -match "\d+\.\d+\.\d+\.\d+"}
				$IsDHCPEnabled = $Network.DHCPEnabled
				$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
				$DNScount = 0
				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
				$OutputObj
			} 
		} 
	} 
	$CombinedOutput | ConvertTo-Html -As List -Head $Head -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
} 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Suresh KumarAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.