locked
"System.Object[]" RRS feed

  • Question

  • Hello,

    I am trying to pull some data to export the csv file but i am having problem with some of the columns comes back as ""System.Object[]"" when i try to export the csv.


    Here is my script"

    #############
    # CSV File Variables #
    #############
    $filelocation="C:\temp\dataexport.csv"
    $response_file = @()
    $date=get-date
    
    #############################
    # Get-Compute nodes  Information        #
    Write-Host -ForegroundColor Yellow "It May Take 10 minutes to run"
    #############################
    #Get-ComputeNodes -Location Tools to get only Tools servers. 
    Get-LXCAComputeNode | `
    		ForEach-Object {
    			$CN = $_
    			$Policy = Get-LXCASystemCompliance -SystemUuid $_.UUID -SystemType ComputeNode
    			$Report = "" | Select-Object Name,SerialNumber,MachineType,ProductName,FirmwareComponentName,FirmwareComponentID,FirmwareCompliant,FirmwareReason
    			$Report.Name = $CN.name
    			$Report.SerialNumber = $CN.SerialNumber
    			$Report.MachineType = $CN.MachineType
    			$Report.ProductName = $CN.ProductName
    			$Report.FirmwareComponentName = $Policy.Firmwares | Select ComponentName
    			$Report.FirmwareComponentID = $Policy.Firmwares | Select ComponentID
    			$Report.FirmwareCompliant = $Policy.Firmwares | Select Compliant
    			$Report.FirmwareReason = $Policy.Firmwares | Select Reason
    							
    $Response_file += $Report 
    	}
    $Response_file | sort -Property Name | Export-csv "$filelocation" -NoTypeInformation

    sample output looks like

    "node10","06xxxxx","8737","IBM Flex System x240 Compute Node","System.Object[]","System.Object[]","System.Object[]","System.Object[]"

    Any help greatly appreciated.



    EverydayLearner

    Friday, March 18, 2016 2:38 PM

Answers

  • Replace these:

    FirmwareComponentName =(($Policy.Firmwares_).ComponentName -join '|')
    FirmwareComponentID = (($Policy.Firmwares).ComponentID-join '|')
    FirmwareCompliant = (($Policy.Firmwares).Compliant -join '|')


    \_(ツ)_/

    Friday, March 18, 2016 3:18 PM
  • Thank for your suggestions. Here is what i we have came up with

    # CSV File Variables #
    #############
    $filelocation="C:\temp\dataexport-" + $date + ".csv"
    $date=get-date
    
    #############################
    # Get-Compute nodes  Information        #
    Write-Host -ForegroundColor Yellow "It May Take 10 minutes to run"
    #############################
    #Get-ComputeNodes -Location Tools to get only Tools servers. 
    $response_file = @()
    
    $nodes = Get-LXCAComputeNode
    foreach ($CN in $nodes) {
    	$Firmwares = (Get-LXCASystemCompliance -SystemUuid $CN.UUID -SystemType ComputeNode).Firmwares
    	foreach ($firmware in $Firmwares){
    		$Report = "" | Select-Object Name,SerialNumber,MachineType,ProductName,FirmwareComponentName,FirmwareFixid,FirmwareCompliant,FirmwareReason
    		$Report.Name = $CN.name
    		$Report.SerialNumber = $CN.SerialNumber
    		$Report.MachineType = $CN.MachineType
    		$Report.ProductName = $CN.ProductName
    		$Report.FirmwareComponentName = $firmware.ComponentName
    		$Report.FirmwareFixid = $firmware.Fixid
    		$Report.FirmwareCompliant = $firmware.Compliant
    		$Report.FirmwareReason = $firmware.Reason
    		$Response_file += $Report 
    	}
    }
    
    
    $Response_file | sort -Property Name | Export-csv "$filelocation" -NoTypeInformation


    EverydayLearner

    Friday, March 25, 2016 2:47 PM

All replies

  • This is all wrong. Where did you get it?

    Dan

    Friday, March 18, 2016 2:45 PM
  • Hi Orhan,

    this is what happens when you try to export a property to csv that is actually a list of values (no matter the number of items in the list). Also, to get a specific property only from an object, you need to expand it.

    You can fix this combining the list entries similar to this:

    # Old line
    $Report.FirmwareComponentName = $Policy.Firmwares | Select ComponentName
    
    # New line
    $Report.FirmwareComponentName = ($Policy.Firmwares | Select -expand ComponentName) -join ", "

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Friday, March 18, 2016 2:57 PM
  • I create the script. am i using wrong logic here?

    EverydayLearner

    Friday, March 18, 2016 2:58 PM
  • Try it this way:

    #############
    # CSV File Variables #
    #############
    $filelocation = 'C:\temp\dataexport.csv'
    $date = get-date
    
    #############################
    # Get-Compute nodes  Information        #
    Write-Host 'It May Take 10 minutes to run' -ForegroundColor Yellow
    #############################
    #Get-ComputeNodes -Location Tools to get only Tools servers. 
    Get-LXCAComputeNode |
    	ForEach-Object {
    		$Policy = Get-LXCASystemCompliance -SystemUuid $_.UUID -SystemType ComputeNode
    		[PSCustomObject]@{
    			Name = $CN.name
    			SerialNumber = $_.SerialNumber
    			MachineType = $_.MachineType
    			ProductName = $_.ProductName
    			FirmwareComponentName = ($Policy.Firmwares_).ComponentName
    			FirmwareComponentID = ($Policy.Firmwares).ComponentID
    			FirmwareCompliant = ($Policy.Firmwares).Compliant
    			FirmwareReason = ($Policy.Firmwares).Reason
    		}
    	} | Export-csv $filelocation -NoTypeInformation


    \_(ツ)_/

    Friday, March 18, 2016 3:03 PM
  • I got the same results unfortunately.

    EverydayLearner

    Friday, March 18, 2016 3:13 PM
  • I got the same results unfortunately.

    EverydayLearner

    Not enough info.  Where are you seeing this.  Post a sample.


    \_(ツ)_/

    Friday, March 18, 2016 3:15 PM
  • Try it this way:

    #############
    # CSV File Variables #
    #############
    $filelocation = 'C:\temp\dataexport.csv'
    $date = get-date
    
    #############################
    # Get-Compute nodes  Information        #
    Write-Host 'It May Take 10 minutes to run' -ForegroundColor Yellow
    #############################
    #Get-ComputeNodes -Location Tools to get only Tools servers. 
    Get-LXCAComputeNode |
    	ForEach-Object {
    		$Policy = Get-LXCASystemCompliance -SystemUuid $_.UUID -SystemType ComputeNode
    		[PSCustomObject]@{
    			Name = $CN.name
    			SerialNumber = $_.SerialNumber
    			MachineType = $_.MachineType
    			ProductName = $_.ProductName
    			FirmwareComponentName = ($Policy.Firmwares_).ComponentName
    			FirmwareComponentID = ($Policy.Firmwares).ComponentID
    			FirmwareCompliant = ($Policy.Firmwares).Compliant
    			FirmwareReason = ($Policy.Firmwares).Reason
    		}
    	} | Export-csv $filelocation -NoTypeInformation


    \_(ツ)_/

    hmmi got different result but still getting ""System.Object[]""  on those fields. When i do

    $policy.firmwares

    Here is that it returns

    ComponentName    : LSI2004
    ComponentID      : 0EDCCAF88B9711E4B2C6000AF7562CA0:LSI2004
    Category         : SAS
    Fixid            : ibm_fw_mpt2sas_x240-1.18.02_linux_32-64
    Build            :
    Date             :
    Version          :
    InstalledBuild   :
    InstalledDate    :
    InstalledVersion :
    Compliant        : yes
    Reason           : The installed version is not down level than the version defined in compliance policy.
    
    ComponentName    : IMM2 (Primary)
    ComponentID      : 0EDCCAF88B9711E4B2C6000AF7562CA0:IMM2 (Primary)
    Category         : IMM2
    Fixid            : ibm_fw_imm2_1aoo66o-4.90_anyos_noarch
    Build            : 1AOO66O
    Date             : 2015-04-25
    Version          :
    InstalledBuild   :
    InstalledDate    :
    InstalledVersion :
    Compliant        : no
    Reason           : The installed version is down level than the version defined in compliance policy.
    
    ComponentName    : UEFI (Backup)
    ComponentID      : 0EDCCAF88B9711E4B2C6000AF7562CA0:UEFI (Backup)
    Category         : UEFI
    Fixid            : ibm_fw_uefi_b2e146h-1.60_anyos_32-64
    Build            : B2E146H
    Date             : 2015-04-03
    Version          :
    InstalledBuild   :
    InstalledDate    :
    InstalledVersion :
    Compliant        : no


    EverydayLearner

    Friday, March 18, 2016 3:15 PM
  • Replace these:

    FirmwareComponentName =(($Policy.Firmwares_).ComponentName -join '|')
    FirmwareComponentID = (($Policy.Firmwares).ComponentID-join '|')
    FirmwareCompliant = (($Policy.Firmwares).Compliant -join '|')


    \_(ツ)_/

    Friday, March 18, 2016 3:18 PM
  • sample output:

    "Name","SerialNumber","MachineType","ProductName","FirmwareComponentName","FirmwareComponentID","FirmwareCompliant","FirmwareReason"
    "node14","06FFRRF","8737","IBM Flex System x240 Compute Node","System.Object[]","System.Object[]","System.Object[]","System.Object[]"
    "node14","06FFRRP","8737","IBM Flex System x240 Compute Node","System.Object[]","System.Object[]","System.Object[]","System.Object[]"
    "node14","06FFRRH","8737","IBM Flex System x240 Compute Node","System.Object[]","System.Object[]","System.Object[]","System.Object[]"
    "node14","06FFRRE","8737","IBM Flex System x240 Compute Node","System.Object[]","System.Object[]","System.Object[]","System.Object[]"

    also you can see that the node name returns the same but the serial number are different which should be the same.


    EverydayLearner

    Friday, March 18, 2016 3:20 PM
  • Thank for your suggestions. Here is what i we have came up with

    # CSV File Variables #
    #############
    $filelocation="C:\temp\dataexport-" + $date + ".csv"
    $date=get-date
    
    #############################
    # Get-Compute nodes  Information        #
    Write-Host -ForegroundColor Yellow "It May Take 10 minutes to run"
    #############################
    #Get-ComputeNodes -Location Tools to get only Tools servers. 
    $response_file = @()
    
    $nodes = Get-LXCAComputeNode
    foreach ($CN in $nodes) {
    	$Firmwares = (Get-LXCASystemCompliance -SystemUuid $CN.UUID -SystemType ComputeNode).Firmwares
    	foreach ($firmware in $Firmwares){
    		$Report = "" | Select-Object Name,SerialNumber,MachineType,ProductName,FirmwareComponentName,FirmwareFixid,FirmwareCompliant,FirmwareReason
    		$Report.Name = $CN.name
    		$Report.SerialNumber = $CN.SerialNumber
    		$Report.MachineType = $CN.MachineType
    		$Report.ProductName = $CN.ProductName
    		$Report.FirmwareComponentName = $firmware.ComponentName
    		$Report.FirmwareFixid = $firmware.Fixid
    		$Report.FirmwareCompliant = $firmware.Compliant
    		$Report.FirmwareReason = $firmware.Reason
    		$Response_file += $Report 
    	}
    }
    
    
    $Response_file | sort -Property Name | Export-csv "$filelocation" -NoTypeInformation


    EverydayLearner

    Friday, March 25, 2016 2:47 PM