title: Custom Objects to CSV PowerShell
body: <pre><code>  #Function to get the computerlist: Name,OS,IPv4, IPv6,DiskInfo
   function Get-ComputerListnDiskInfo{
   [CmdletBinding()]
    param(
    [Parameter(ValueFromPipeline=$True)] [string[]]$ComputerName 
    )
    BEGIN {
      Import-Module ActiveDirectory -Cmdlet Get-ADComputer -ErrorAction SilentlyContinue
    }
    PROCESS {
  
      try{
          $computerinfo = Get-ADComputer -Filter * -Properties OperatingSystem
          #Information about Name,Ipv4,IPv6,Device,VolumeName,Free,Busy,Size,Pfree,Pbusy for ALL COMPUTERS container
          $AllComputerInfo = @()
          foreach ($comp in $computerinfo){
              #Testing if computers is ON LINE
              $TestCon = Tester $comp.name
              $test = $TestCon.BooleanV
              if($test) {
                  #write-output "$Test"
                  $PhysicalDisks = Get-WMIObject -computername $comp.name -query "SELECT * from win32_logicaldisk where DriveType = 3" | Select Deviceid,VolumeName,FreeSpace,Size
                  $Target = @()
                  #Create the Object foreach disk and append in the Target Variable
                  $GetOPNHealthStatus = Get-PhysicalDisk | select FriendlyName,OperationalStatus,HealthStatus
  
                  Write-Output "$PhysicalDisk.count"
  
                  #write-output $GetOPNHealthStatus.OperationalStatus
                  $i=0
                  foreach ($disk in $physicalDisks){
  
                      #Get all Items: size,free,busy,pfree and pbusy disk space info (can add a number at the end to set decimals)
                      $Size=FormatNSetSizeFreeSpace $disk.Size
                      $Free=FormatNSetSizeFreeSpace $disk.FreeSpace
                      $Busy=FormatNSetBusySpace $disk.Size $disk.FreeSpace
                      $Pfree=PercentFreeBusy $Free $size
                      $PBusy=PercentFreeBusy $Busy $size
  
                      #Create a new Object using all the info
                      $result =New-Object PSObject -Property @{
                          Device=$disk.DeviceID
                          VolumeName=$disk.VolumeName
                          Size=$Size
                          Free=$Free
                          Busy=$Busy
                          Pfree = $PFree
                          PBusy = $PBusy
                          OPStatus = $GetOPNHealthStatus.OperationalStatus[$i]
                          HStatus  = $GetOPNHealthStatus.HealthStatus[$i]
                      }
  
                      $i++
                      #add this info to the target array
                      $Target+= $result
                  }
  
  
                      #Add all info into new object
                      $allIComnDiskInfo=New-Object PSObject -Property @{
                          Name = $comp.Name
                          OS = $comp.OperatingSystem
                          IPV4 =  $TestCon.IPv4
                          IPV6 =  $TestCon.IPv6
                          disksInfo = $Target
                      }
                  #and Fill any just add this info to the $Allcomputer info (just online computer's)
                  $AllComputerInfo+= $allIComnDiskInfo
              }   
          }
          return $AllComputerInfo
      }
      Catch{
          Write-Warning $_.Exception.Message
      }
    }
  }
  
  $test = Get-ComputerListnDiskInfo
  </code></pre>
  
  <p>running $test</p>
  
  <pre><code>$test = Get-ComputerListnDiskInfo
  </code></pre>
  
  <p>$test</p>
  
  <pre><code>disksInfo : {@{PBusy=8,148; VolumeName=; Busy=10,306; Pfree=91,853; Free=116,178; Device=C:; Size=126,483; OPStatus=O; HStatus=H}}
  Name      : DC2012
  OS        : Windows Server 2012 R2 Standard
  IPV4      : 192.168.1.251
  IPV6      : fe80::cd63:76bf:3d2b:340f%12
  </code></pre>
  
  <p>And running </p>
  
  <pre><code>$test | Export-Csv here.csv
  </code></pre>
  
  <p>I got this:</p>
  
  <pre><code>#TYPE System.String
  "Length"
  "6"
  </code></pre>
  
  <p>Why is happening this?</p>
  
  <p>Why I don't get all this info?</p>
  
  <p>And how should I search the info contained in the "diskInfo" variable </p>
  
  <p>I tried to pass this $test variable to another function to format it and It seem not to work:</p>
  
  <p>Thank you in advance for the answers </p>