Invoke-Command and RichTextBox

How would I get the following to display to RichTextBox?

$Servers = Get-ADComputer -Filter * SearchBase “OU=IT,DC=Contoso,DC=Com” | Select-Object -ExpandProperty Name

Invoke-Command -ComputerName $Server.name -ScriptBlock { Get-ItemProperty “HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall*” } | select PSComputerName, DisplayVersion | where ( $_.DisplayName -match “Symantec Endpoint Encryption” } | Out-String

I had it in a foreach loop before realizing it wasn’t necessary.

Hello CM,

Have you already reviewed this article?

https://docs.microsoft.com/en-us/previous-versions/technet-magazine/cc510337(v=msdn.10)

From (

@cm is this question a continuation of

https://powershell.org/forums/topic/script-works-in-poweshell-but-not-ps-studio/
?

You could have asked for an update in the same thread.

You can save the output of Invoke-Command to a variable and use the variable to set the richtextbox.

Do you have any code that you have already tried to add it to the RichTextBox ?

Lot of information missing here such as what you’re currently working with in your GUI script. Here’s a crude example that shows how to make a button click run a command and output the text into a rich textbox.

 

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

#region begin GUI{

$Form                            = New-Object system.Windows.Forms.Form
$Form.ClientSize                 = '800,400'
$Form.text                       = "Form"
$Form.TopMost                    = $false

$TextBox1                        = New-Object System.Windows.Forms.RichTextBox
$TextBox1.multiline              = $true
$TextBox1.width                  = 706
$TextBox1.height                 = 206
$TextBox1.location               = New-Object System.Drawing.Point(40,45)
$TextBox1.Font                   = 'Lucida Console,10'

$Button1                         = New-Object system.Windows.Forms.Button
$Button1.text                    = "Go"
$Button1.width                   = 60
$Button1.height                  = 30
$Button1.location                = New-Object System.Drawing.Point(37,280)
$Button1.Font                    = 'Microsoft Sans Serif,10'

$Form.controls.AddRange(@($TextBox1,$Button1))



#Write your logic code here
$Button1.Add_Click({$TextBox1.text = "Running your ScriptBlock..."
		            $Servers = Get-ADComputer -Filter * SearchBase "OU=IT,DC=Contoso,DC=Com" | Select-Object -ExpandProperty Name
			        $result = Invoke-Command -ComputerName $Server.name -ScriptBlock { Get-ItemProperty "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" } | select PSComputerName, DisplayVersion | where ( $_.DisplayName -match "Symantec Endpoint Encryption" } | Out-String
		            $TextBox1.text = $result
		          })

#
[void]$Form.ShowDialog()

 

@kevprassoon Hello. I have already tried trapping the invoke-command in a variable and then outputting to a richtextbox. When I run the script nothing will display.

I did $Results = Invoke-Command… and then

Richtextbox_output.text = $Results

As an alternative or work around I can search and see if the service is running with Get-Service.