Link to home
Start Free TrialLog in
Avatar of Suresh Kumar
Suresh Kumar

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Suresh Kumar
Suresh Kumar

ASKER

thanks