Excel CSV file not work

Hello,my workmate give a code to find how to export to excel csv file, i was checking the code and i change the path of the file but when i add an extension to this path, it gives me an error that says " you cannot add csv content to (file path) if you cannot finde incidencer use force command and restart, this is the code.

$Computers = Get-ADComputer -filter * |Select-Object -ExpandProperty Name
      Foreach($computer in $computers){
if(!(Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
     {write-host "cannot reach $computer offline" -f red}
      else {
$outtbl = @()
Try{
$Xr=Get-WmiObject –class Win32_processor -ComputerName $computer -ErrorAction Stop   
$di=Get-WmiObject -class win32_logicaldisk -ComputerName $computer -ErrorAction stop | Format-Table DeviceId, MediaType, @{n="Size";e={[math]::Round($_.Size/1GB,2)}},@{n="FreeSpace";e={[math]::Round($_.FreeSpace/1GB,2)}}
$ld=get-adcomputer $computer -properties Name,Lastlogondate,operatingsystem,ipv4Address,enabled,description,DistinguishedName -ErrorAction Stop
$r="{0} GB" -f ((Get-WmiObject Win32_PhysicalMemory -ComputerName $computer |Measure-Object Capacity  -Sum).Sum / 1GB)
$x = gwmi win32_computersystem -ComputerName $computer |select @{Name = "Type";Expression = {if (($_.pcsystemtype -eq '2')  ) 

{'Laptop'} Else {'Desktop Or Other something else'}}},Manufacturer,@{Name = "Model";Expression = {if (($_.model -eq "$null")  ) {'Virtual'} Else {$_.model}}},username -ErrorAction Stop
$t= New-Object PSObject -Property @{
    computername = $ld.Name
    diskspace = $di.diskspace
    Ipaddress=$ld.IPv4Address
    Enabled=$ld.Enabled
    Description=$ld.Description
    Ou=$ld.DistinguishedName.split(',')[1].split('=')[1] 
    Type = $x.type
    Manufacturer=$x.Manufacturer
    Model=$x.Model
    Ram=$R
    ProcessorName=($xr.name | Out-String).Trim()
    NumberOfCores=($xr.NumberOfCores | Out-String).Trim()
    NumberOfLogicalProcessors=($xr.NumberOfLogicalProcessors | Out-String).Trim()
    Addresswidth=($xr.Addresswidth | Out-String).Trim()
    Operatingsystem=$ld.operatingsystem
    Lastlogondate=$ld.lastlogondate
    LoggedinUser=$x.username
    }
    $outtbl += $t
    }
    catch [Exception]
    {
        "Error communicating with $computer, skipping to next"   
    }
   $outtbl | select Computername,diskspace, enabled,description,ipAddress,Ou,Type,Serialnumber,Manufacturer,Model,Ram,ProcessorName,NumberOfCores,NumberOfLogicalProcessors,Addresswidth,Operatingsystem,loggedinuser,Lastlogondate |export-csv -Append C:\temp\inventario.csv  -nti
}
}

Andrés,

if you got this code from a workmate and want to change or improve it the first and best one to ask for should be your workmate. :wink:

You should collect the output of your outer most loop in a variable and pipe this variable to Export-CSV.