Page 1 of 2

output issues

Posted: Mon Oct 29, 2018 1:25 pm
by mqh77777
We have a PowerShell Studio form that collects lots of data from machines. We are trying to gather TPM information from machines. So I added a button that has this code behind it.

Code: Select all

$buttonTPMStatus_Click={
$statusbar1.text = 'Getting TPM status, please wait...'
$richtextbox_output.Clear()
$TPM = Invoke-Command -ComputerName $TextPC -ScriptBlock {
Get-Tpm | Select-Object PSComputerName, RunspaceId, TpmPresent, TpmReady, ManufacturerId, ManufacturerIdTxt, ManufacturerVersion, ManufacturerVersionFull20, ManagedAuthLevel, OwnerAuth, OwnerClearDisabled, AutoProvisioning, LockedOut, LockoutHealTime, LockoutCount, LockoutMax } | Out-String
$richtextbox_output.AppendText($TPM)
$statusbar1.text = 'All done!'
}
When I run this it only returns the following in the RichTextBox
TpmPresent : True
TpmReady : False
ManufacturerId : 1464156928
ManufacturerIdTxt : WEC

Why? When I run the same code in PowerShell ISE it returns this.

Code: Select all

TpmPresent                : True
TpmReady                  : False
ManufacturerId            : 1464156928
ManufacturerIdTxt         : WEC 
ManufacturerVersion       : 5.81 
ManufacturerVersionFull20 : Not Supported for TPM 1.2
ManagedAuthLevel          : Full
OwnerClearDisabled        : True
AutoProvisioning          : Enabled
LockedOut                 : False
LockoutHealTime           : Not Supported for TPM 1.2
LockoutCount              : Not Supported for TPM 1.2
LockoutMax                : Not Supported for TPM 1.2
PSComputerName            : bo-fao4r46ch2-d
RunspaceId                : a0970be0-1e88-46a1-8169-4525f5a2f02f

Re: output issues

Posted: Mon Oct 29, 2018 2:05 pm
by jvierra
Works fine for me. Perhaps you need a bigger textbox.

I would do it this way:

Code: Select all

$props = @(
    'PSComputerName', 
    'RunspaceId', 
    'TpmPresent', 
    'TpmReady', 
    'ManufacturerId', 
    'ManufacturerIdTxt', 
    'ManufacturerVersion', 
    'ManufacturerVersionFull20', 
    'ManagedAuthLevel', 
    'OwnerAuth', 
    'OwnerClearDisabled', 
    'AutoProvisioning', 
    'LockedOut', 
    'LockoutHealTime', 
    'LockoutCount', 
    'LockoutMax'
)
$buttonGetTPM_Click={
    $statusbar1.text = 'Getting TPM status, please wait...'
    $richtextbox_output.Clear()
    $tpm_lines = Invoke-Command -ComputerName $computer.Text -ScriptBlock {Get-Tpm } | 
            Select-Object $props | Out-String
    $richtextbox_output.Lines = $tpm_lines
    $statusbar1.text = 'All done!'
}

Re: output issues

Posted: Mon Oct 29, 2018 2:11 pm
by mqh77777
using your code my output looks like this:

Code: Select all

PSComputerName            : mypc
RunspaceId                : f0b08ec5-02d8-4a4c-8b71-d3ead76f3840
TpmPresent                : True
TpmReady                  : False
ManufacturerId            : 1464156928
ManufacturerIdTxt         : WEC
My richtextbox output window is big enough. Plus it will scroll. I have other buttons that dump hundreds of lines into it and they all display.

Re: output issues

Posted: Mon Oct 29, 2018 2:21 pm
by jvierra
Post the exact code you used. My code does not do that when I run it.

Re: output issues

Posted: Mon Oct 29, 2018 2:30 pm
by mqh77777
I have put the array both inside and outside of the ButtonClick Event. I get the same results.

Code: Select all

$props = @(
	'PSComputerName',
	'RunspaceId',
	'TpmPresent',
	'TpmReady',
	'ManufacturerId',
	'ManufacturerIdTxt',
	'ManufacturerVersion',
	'ManufacturerVersionFull20',
	'ManagedAuthLevel',
	'OwnerAuth',
	'OwnerClearDisabled',
	'AutoProvisioning',
	'LockedOut',
	'LockoutHealTime',
	'LockoutCount',
	'LockoutMax'
)

$buttonTPMStatus_Click = {
		$statusbar1.text = 'Getting TPM status, please wait...'
		$richtextbox_output.Clear()
		$tpm_lines = Invoke-Command -ComputerName $PCNameBox.Text -ScriptBlock { Get-Tpm } |
		Select-Object $props | Out-String
		$richtextbox_output.Lines = $tpm_lines
		$statusbar1.text = 'All done!'

}

Re: output issues

Posted: Mon Oct 29, 2018 2:34 pm
by jvierra
Works fine for me. Set all RTB properties back to default and try again. Be sure "Multiline" is set to $true.

Re: output issues

Posted: Tue Oct 30, 2018 6:56 am
by mqh77777
Product: PowerShell Studio 2018 (64 Bit)
Build: v5.5.155
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.16299.0

I created a brand new form that has 1 button and 1 richtextbox. All RTB properties are set to default.

I have this code.

Code: Select all

$button1_Click={
	if (test-path c:\temp\tpm.txt) { remove-item c:\temp\tpm.txt }
	$statusbar1.text = 'Getting TPM status, please wait...'
	$richtextbox1.Clear()
	Invoke-Command -ComputerName "MyComputer" -ScriptBlock { Get-Tpm } | Out-File c:\temp\TPM.txt
	$GetTPMData = Get-Content c:\temp\tpm.txt
	$GetTPMData | Out-String
	$richtextbox1.AppendText($GetTPMData)
	$statusbar1.text = 'All done!'
}
The TPM.txt file gets created and looks like this: (note: there are several blank lines at the top)

Code: Select all



PSComputerName            : MyComputer
RunspaceId                : eea87612-e378-4e3e-ba53-3aa7b6ddfc76
TpmPresent                : True
TpmReady                  : False
ManufacturerId            : 1464156928
ManufacturerIdTxt         : WEC 
ManufacturerVersion       : 5.81 
ManufacturerVersionFull20 : Not Supported for TPM 1.2
ManagedAuthLevel          : Full
OwnerAuth                 : 
OwnerClearDisabled        : False
AutoProvisioning          : Enabled
LockedOut                 : False
LockoutHealTime           : Not Supported for TPM 1.2
LockoutCount              : Not Supported for TPM 1.2
LockoutMax                : Not Supported for TPM 1.2
SelfTest                  : {255, 1, 2, 5...}
Yet what is displayed in the RTB is this:

Code: Select all

  PSComputerName            : MyComputer RunspaceId                : 4c267e6d-27b7-4b7c-b7e9-ed5358ac1331 TpmPresent                : True TpmReady                  : False ManufacturerId            : 1464156928 ManufacturerIdTxt         : WEC

Re: output issues

Posted: Tue Oct 30, 2018 8:06 am
by jvierra
Yes - the TPM object cannot be displayed in a form correctly. I can reproduce the results.

The issue is that the middle of the results contains a large string of null characters which breaks the output. Open the file in a binary editor to see what I mean.

Re: output issues

Posted: Tue Oct 30, 2018 8:13 am
by jvierra
Here is a work-around:

Code: Select all

$buttonGetTPM_Click={
    $statusbar1.text = 'Getting TPM status, please wait...'
    $tpm_lines = Invoke-Command -ComputerName alpha -ScriptBlock {  Get-Tpm }     
    $richtextbox_output.Lines = $tpm_lines[0] | Out-String | %{$_ -replace '\0'}
    $statusbar1.text = 'All done!'
}

Re: output issues

Posted: Tue Oct 30, 2018 4:34 pm
by jvierra
Also this works:

Code: Select all

$props = @(
    'PSComputerName', 
    'RunspaceId', 
    'TpmPresent', 
    'TpmReady', 
    'ManufacturerId', 
    'ManufacturerIdTxt', 
    #'ManufacturerVersion', 
    #'ManufacturerVersionFull20', 
    'ManagedAuthLevel', 
    'OwnerAuth', 
    'OwnerClearDisabled', 
    'AutoProvisioning', 
    'LockedOut', 
    'LockoutHealTime', 
    'LockoutCount', 
    'LockoutMax'
)
$buttonGetTPM_Click={
    $statusbar1.text = 'Getting TPM status, please wait...'
    $tpm_lines = Invoke-Command -ComputerName MyPC-ScriptBlock { Get-Tpm }      
    $richtextbox_output.Lines = $tpm_lines | Select $props |Out-String 
    $statusbar1.text = 'All done!'
}