Output Format

This topic contains 6 replies, has 3 voices, and was last updated by Profile photo of Adarsh Adarsh 1 month ago.

  • Author
    Posts
  • #67096
    Profile photo of Adarsh
    Adarsh
    Participant

    Using Write-Output in foreach loop, I'm getting output in below format

    Write-Output $a,$b,$c,$d | FT -Property Manu, State, Driver, DState, Model, MState, Firmware, Firmstate -Autosize
    
    Output
    
    Manu   State    Driver     DState    Model    MState Firmware   Firmstate
    -----  ------   ---------- -------  --------- ------ --------   -------
    {Dell} {Passed}
                    10.56.XX.XX  {Passed}
                                          LPXXXXXx {Failed}
                                                            11.50.60.34 {Failed}
    
    Manu   State    Driver     DState    Model    MState Firmware   Firmstate
    -----  ------   ---------- -------  --------- ------ --------   -------
    {Dell} {Passed}
                    10.56.XX.XX  {Passed}
                                          LPXXXXXx {Failed}
                                                            11.50.60.34 {Failed}
    
    Manu   State    Driver     DState    Model    MState Firmware   Firmstate
    -----  ------   ---------- -------  --------- ------ --------   -------
    {Dell} {Passed}
                    10.56.XX.XX  {Passed}
                                          LPXXXXXx {Failed}
                                                            11.50.60.34 {Failed}
    
    

    How can I format the object in single line as shown below.
    Manu State Driver DState Model MState Firmware Firmstate
    —– —— ———- ——- ——— —— ——– ——-
    {Dell} {Passed} 10.56.XX.XX {Passed}LPXXXXXx {Failed}11.50.60.34 {Failed}

    Thanks,

  • #67113
    Profile photo of Sam Boutros
    Sam Boutros
    Participant
    @($a,$b,$c,$d) | FT Manu, State, Driver, DState, Model, MState, Firmware, Firmstate -Auto
    
  • #67147
    Profile photo of Adarsh
    Adarsh
    Participant

    Thanks Sam. Still, I'm not getting output in correct format.

  • #67332
    Profile photo of Max Kozlov
    Max Kozlov
    Participant

    can you show what values in $a,$b,$c,$d ?

    • #67443
      Profile photo of Adarsh
      Adarsh
      Participant
      $WMI_XX = fetching system content using WMI query
      $conf_XX = parsing xml config file entries.
      
      foreach ($hba in $hbas) {
      
      	if ($WMI_Manufacturer -in $conf_Manufacturer) {
      	$props = @{ Manu =$WMI_Manufacturer
      	State = "Passed" }
      	$a = New-Object -TypeName PSObject -Property $props
      	}
      	else {
      	$props = @{ Manu =$WMI_Manufacturer
      	State = "failed" }
      	$a = New-Object -TypeName PSObject -Property $props
      	}
      	
      	if ($WMI_Model -in $conf_Model) {
      	$props1 = @{ Model =$WMI_Model
      	State = "Passed" }
      	$b = New-Object -TypeName PSObject -Property $props
      	}
      	else {
      	$props1 = @{ Model =$WMI_Model
      	MState = "failed" }
      	$b = New-Object -TypeName PSObject -Property $props1
      	}
      	if ($WMI_Driver-in $conf_Driver) {
      	$props2 = @{ Driver =$WMI_Driver
      	DState = "Passed" }
      	$c = New-Object -TypeName PSObject -Property $props2
      	}
      	else {
      	$props = @{ Driver =$WMI_Driver
      	MState = "failed" }
      	$c = New-Object -TypeName PSObject -Property $props2
      	}
      	if ($WMI_Firm-in $conf_Firm) {
      	$props3 = @{ FirmVersion =$WMI_Firm
      	Firmstate = "Passed" }
      	$d = New-Object -TypeName PSObject -Property $props3
      	}
      	else {
      	$props3 = @{ FirmVersion =$WMI_Firm
      	Firmstate = "failed" }
      	$d = New-Object -TypeName PSObject -Property $props2
      	}
      Write-Output $a,$b,$c,$d | FT -Property Manu, State, Driver, DState, Model, MState, Firmware, Firmstate -Autosize
      
      }
      
  • #67446
    Profile photo of Max Kozlov
    Max Kozlov
    Participant

    what you want is what you get 🙂
    you create several objects with two properties each.
    but you need one object with many properties

    $WMI_XX = fetching system content using WMI query
    $conf_XX = parsing xml config file entries.
    
    foreach ($hba in $hbas) {
        $props = @{
           Manu = $WMI_Manufacturer
           Model = Model =$WMI_Model
           Driver =$WMI_Driver
           FirmVersion =$WMI_Firm
        }
    	$props['State'] = if ($WMI_Manufacturer -in $conf_Manufacturer) { 'Passed' } else { 'Failed' }
    	$props['MSatte'] = if ($WMI_Model -in $conf_Model) { 'Passed' } else { 'Failed' }
    	$props['DState'] = if ($WMI_Driver-in $conf_Driver) { 'Passed' } else { 'Failed' }
            $props['Firmstate'] = if ($WMI_Firm-in $conf_Firm) { 'Passed' } else { 'Failed' }
    	New-Object -TypeName PSObject -Property $props
    } |
    		FT -Property Manu, State, Driver, DState, Model, MState, Firmware, Firmstate -Autosize
    
    • #67453
      Profile photo of Adarsh
      Adarsh
      Participant

      Thanks Max for your help.

You must be logged in to reply to this topic.