Author Posts

March 23, 2017 at 6:18 pm

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,

March 23, 2017 at 8:07 pm

@($a,$b,$c,$d) | FT Manu, State, Driver, DState, Model, MState, Firmware, Firmstate -Auto

March 24, 2017 at 3:18 am

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

March 27, 2017 at 10:31 am

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

March 28, 2017 at 7:13 am

$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

}

March 28, 2017 at 7:51 am

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

March 28, 2017 at 1:38 pm

Thanks Max for your help.