The property 'Text' cannot be found on this object.

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 3 months and 1 week 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
budder1975
Posts: 4
Last visit: Mon Aug 26, 2024 8:33 am

The property 'Text' cannot be found on this object.

Post by budder1975 »

  1.                 $Applications = (Get-WmiObject -Namespace "root\ccm\clientSDK" -Class CCM_SoftwareUpdate -ComputerName $Computer | Sort-Object name)
  2.                
  3.                 if ([string]::IsNullOrEmpty($Applications))
  4.                 {
  5.                     write-host "$computer,No Pending updates found." -ForegroundColor Yellow;
  6.                     $textbox1.Text = "No pending updates found."
  7.                 }

Code: Select all

PS Studio 5.8.247.0
Server 2022 21h2

I keep getting text errors from both a label and a text box similar to this:
ERROR: The property 'Text' cannot be found on this object. Verify that the property exists and can be set.

I looked over several different topics with similar issues and it may be something related to the scope of the script, but my understanding was this the script runs in a global scope. However, I did have to set up a $script:variableName in order for another variable to pass along the relevant details. I validated I am using the correct syntax with this basic one liner in the $formMain_Load section:

$textbox1.Text = "Status"

From that point it never updates with new $textbox1.Text data. Here's a small snippet in a $buttonLoad_Click event:

$Applications = (Get-WmiObject -Namespace "root\ccm\clientSDK" -Class CCM_SoftwareUpdate -ComputerName $Computer | Sort-Object name)

if ([string]::IsNullOrEmpty($Applications))
{
write-host "$computer,No Pending updates found." -ForegroundColor Yellow;
$textbox1.Text = "No pending updates found."
}

Then I get this message:

ERROR: The property 'Text' cannot be found on this object. Verify that the property exists and can be set.
ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
ERROR: + FullyQualifiedErrorId : PropertyNotFound
ERROR: + PSComputerName : lhl385737
ERROR:

Hopefully I am used PS studio correctly and have this syntax in the right spot. If not, please enlighten me.
Thanks very much, good people.[Codebox=text file=Untitled.txt]
budder1975
Posts: 4
Last visit: Mon Aug 26, 2024 8:33 am

Re: The property 'Text' cannot be found on this object.

Post by budder1975 »

  1. Apologies. Correction, this is ran from a $checkForMissingUpdatesToolStripMenuItem_Click event.
budder1975
Posts: 4
Last visit: Mon Aug 26, 2024 8:33 am

Re: The property 'Text' cannot be found on this object.

Post by budder1975 »

I figured out that the context missing the property is because I am using Invoke-Command on remote computers.

So I have tried out-host, result, and others to pull the $result out of the remote machine bring it back into the main session, but all of them seem to fail. I am aware this isn't a PS studio issue but is because of my own hack syntax, any help with this is would be greatly appreciated :)

This isn't the full script and some things are merely placeholders.
  1. $checkForMissingUpdatesToolStripMenuItem_Click={
  2. $script:dest = $datagridviewResults.CurrentCell.Value
  3.    
  4.     Invoke-Command -ComputerName $Dest -ScriptBlock {
  5.         $computers = $env:COMPUTERNAME
  6.         Foreach ($script:Computer in $computers)
  7.         {
  8.                          ## Added these two lines to test if the error goes away, which they do. But still no output to the local session, if I recall from yesterday :)
  9.             #add-type -AssemblyName System.Windows.Forms
  10.             #$textbox1 = New-Object System.Windows.Forms.TextBox
  11.             try
  12.             {
  13.                 $ErrorActionPreference = "stop"            
  14.                 $Applications = (Get-WmiObject -Namespace "root\ccm\clientSDK" -Class CCM_SoftwareUpdate -ComputerName $Computer | Sort-Object name)
  15.                
  16.                 if ([string]::IsNullOrEmpty($Applications))
  17.                 {
  18.                     write-host "$computer,No Pending updates found."; ## for $computer variable testing, etc. works find
  19.                                          #$result = "$computer,No Pending updates found."
  20.                     $result = "$computer,No Pending updates found." | Out-String;
  21.                     return $result
  22.                 }
  23. Catch{}
  24. Finally{}
  25.  
  26.     $textbox1.Text = "$result"
  27. }
User avatar
brittneyr
Site Admin
Posts: 1805
Last visit: Fri Nov 08, 2024 11:17 am
Answers: 44
Been upvoted: 34 times

Re: The property 'Text' cannot be found on this object.

Post by brittneyr »

If you need the output from the Invoke-Command call, you can save the object returned to a variable. Something like this for example:
  1. $returnedResult =  Invoke-Command -ComputerName $Dest -ScriptBlock {...

You may find the following helpful:
https://www.tutorialspoint.com/how-to-w ... ock-output
Brittney
SAPIEN Technologies, Inc.
budder1975
Posts: 4
Last visit: Mon Aug 26, 2024 8:33 am

Re: The property 'Text' cannot be found on this object.

Post by budder1975 »

Omg, thanks very much. I saw this post scouring the network of networks and simply passed it by, however it worked. Somehow my logic from looking at all the other pages, it seemed to be out of context in my mind. Much appreciated.
Bill
This topic is 3 months and 1 week 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