output issues

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

output issues

Post 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: output issues

Post 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!'
}
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: output issues

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: output issues

Post by jvierra »

Post the exact code you used. My code does not do that when I run it.
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: output issues

Post 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!'

}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: output issues

Post by jvierra »

Works fine for me. Set all RTB properties back to default and try again. Be sure "Multiline" is set to $true.
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: output issues

Post 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: output issues

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: output issues

Post 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!'
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: output issues

Post 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!'
}
This topic is 5 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked