I do not see the correct IP addresses after run the Export-csv powershel cmdlet

Hi folks,
I have a script for inventory data including ip address that do export to csv  file . ip address in the column instead of addresses have a record System.String []. I bring this script completely:

$Machines = Get-Content -Path C:\powershell\scripts\Computers.txt
$AllComputers = @()

foreach ($machine in $machines)
{
    $objCompSys = Get-WmIObject -class "Win32_ComputerSystem" -cn $machine -EA silentlyContinue  -namespace "root\CIMV2"
    $compname = $objCompSys.Name
    $physicalRAM = [Math]::Ceiling($objCompSys.TotalPhysicalMemory / 1GB)
    $CurrentUser = $objCompSys.username  
 
    $objCompOS = Get-WmIObject -class "Win32_OperatingSystem" -cn $machine -EA silentlyContinue  -namespace "root\CIMV2"
    $WindowsVersion = $objCompOS.Caption
    $ServicePack =  $objCompOS.csdversion
    $WinInsDate = $objCompOS.ConvertToDateTime($objCompOS.InstallDate) | Get-Date -Format d                        
 
    $DiskItems = Get-WMIObject -Class Win32_DiskDrive -Filter {DeviceId = '\\\\.\\PHYSICALDRIVE0'} -computername $machine | select -ExpandProperty size
    $DiskSize = $DiskItems.Size/1GB
    $PhyDrive = $objPhydrive.size
 
    $NetAdapters = Get-WmIObject -class "Win32_NetworkAdapterConfiguration" -cn $machine  | where{$_.IPEnabled -eq "True"}
    $IPAddress =   $NetAdapters.IPAddress

    $objProc = Get-WMIObject -class "Win32_Processor" -cn $machine
    $procType = $objProc.Name
     
    $Object = New-Object PSObject -Property @{
 
    CompName     = $compname
    WindowsVersion = $WindowsVersion
    ServicePack = $ServicePack
    WinInsDate = $WinInsDate
    IPAddress = $IPAddress
    CurrentUser = $CurrentUser
 
    ProcType = $procType
    DiskSize = $DiskSize
    MemoryCapacity = $physicalRAM
    #DiskSize = $Item.Size/1024/1024/1024
    # FreeSpace = $Item.FreeSpace/1024/1024/1024
    }
    $AllComputers += $Object
}

Open in new window

$AllComputers | select CompName,IPaddress,WindowsVersion,ServicePack,WinInsDate,CurrentUser,ProcType,DiskSize,MemoryCapacity  | Export-Csv c:\Powershell\change2.csv

Open in new window



  What I have to change in the code to see the IP addresses of computers
nesher13Asked:
Who is Participating?
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.

Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Use the following instead:

Export-Csv c:\Powershell\change2.csv  -NoTypeInformation
0
SreRajCommented:
Hi,

There could be multiple NIC adapters configured with multiple IP addresses on each of the computer. So when you execute,

$NetAdapters = Get-WmIObject -class "Win32_NetworkAdapterConfiguration" -cn $machine  | where{$_.IPEnabled -eq "True"}

it returns multiple adapters, so $NetAdapters becomes an array object. Please try the line

$IPAddresses = foreach($Adapter in $Netadapters){$adapter.ipaddress}

instead of

$IPAddress =   $NetAdapters.IPAddress
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
SubsunCommented:
Probably IPaddress is a multi-valued attribute.. Try..

$AllComputers | select CompName,{$_.IPaddress},WindowsVersion,ServicePack,WinInsDate,CurrentUser,ProcType,DiskSize,MemoryCapacity  | Export-Csv c:\temp\change2.csv

Open in new window

0
Challenges in Government Cyber Security

Has cyber security been a challenge in your government organization? Are you looking to improve your government's network security? Learn more about how to improve your government organization's security by viewing our on-demand webinar!

nesher13Author Commented:
To Subsun:

it does not solve the problem
0
SubsunCommented:
Are you getting a empty output?

What you get as a result when you just print $AllComputers?
0
nesher13Author Commented:
To SreRaj,

thank you very much. it works fine
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.