Add this to your loop :
$NetBiosName = Get-WmiObject Win32_ComputerSystem -ComputerName $Computer | select -ExpandProperty name
$OutputObj | Add-Member -MemberType NoteProperty -Name "NetBiosName" -Value
$NetBiosName
PowerShell V2.0
$InputFile = "c:\servers.txt"
$CsvFile = "c:\results.csv"
$report = @()
ForEach($Computer in (gc -Path $InputFile)){
If(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {
$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPEnabled}
ForEach($Network in $Networks) {
$IPAddress = $Network.IpAddress[0]
$SubnetMask = $Network.IPSubnet[0]
$DefaultGateway = $Network.DefaultIPGateway
}
$MACAddress = $Network.MACAddress
$NetBiosName = Get-WmiObject Win32_ComputerSystem -ComputerName $Computer | select -ExpandProperty name
$OutputObj = New-Object -Type PSObject
$OutputObj | Add-Member -MemberType NoteProperty -Name NetBios -Value $NetBiosName
$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
$OutputObj | Add-Member -MemberType NoteProperty -Name MACAddress -Value $MACAddress
$Report += ,$OutputObj
}
}
Write-Output $report
Or this, but makes the list of properties in a random order... since PS v2.0 doesn't have the [ordered] thing.
$InputFile = "c:\servers.txt"
$CsvFile = "c:\results.csv"
$report = @()
ForEach($Computer in (gc -Path $InputFile)){
If(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {
$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPEnabled}
ForEach($Network in $Networks) {
$IPAddress = $Network.IpAddress[0]
$SubnetMask = $Network.IPSubnet[0]
$DefaultGateway = $Network.DefaultIPGateway
}
$MACAddress = $Network.MACAddress
$NetBiosName = Get-WmiObject Win32_ComputerSystem -ComputerName $Computer | select -ExpandProperty name
$Props = @{
NETBIOS = $NetBiosName
ComputerName = $Computer.ToUpper()
IPAddress = $IPAddress
SubnetMask = $SubnetMask
Gateway = ($DefaultGateway -join ",")
MACAddress = $MACAddress
}
$OutputObj = New-Object -Type PSObject -Property $Props
$Report += ,$OutputObj
}
}
Write-Output $report
Or best if you have PowerShell v.3.0 or later.
$InputFile = "c:\servers.txt"
$CsvFile = "c:\results.csv"
$report = @()
ForEach($Computer in (gc -Path $InputFile)){
If(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {
$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPEnabled}
ForEach($Network in $Networks) {
$IPAddress = $Network.IpAddress[0]
$SubnetMask = $Network.IPSubnet[0]
$DefaultGateway = $Network.DefaultIPGateway
}
$MACAddress = $Network.MACAddress
$NetBiosName = Get-WmiObject Win32_ComputerSystem -ComputerName $Computer | select -ExpandProperty name
$Props = [ordered]@{
NETBIOS = $NetBiosName
ComputerName = $Computer.ToUpper()
IPAddress = $IPAddress
SubnetMask = $SubnetMask
Gateway = ($DefaultGateway -join ",")
MACAddress = $MACAddress
}
$OutputObj = New-Object -Type PSObject -Property $Props
$Report += ,$OutputObj
}
}
Write-Output $report