Script works in Poweshell, but not PS Studio.

Welcome Forums General PowerShell Q&A Script works in Poweshell, but not PS Studio.

This topic contains 4 replies, has 2 voices, and was last updated by

cm
 
Participant
3 days ago.

  • Author
    Posts
  • #113576
    cm

    Participant
    Points: 0
    Rank: Member

    Hello, I have a script that looks at an OU and finds Symantec Version based on the Reg Value and gives me a reporting of ones that match. What do I need to do to get it working in a GUI?

    https://pastebin.com/TtL6RJwq

    I have tried piping to Out-String and then trying to display results to RichTextBox with no results being displayed.

    TIA

  • #113602

    Participant
    Points: 20
    Rank: Member

    You code is just about iterating through a list of servers and getting the reg key values using remoting. Code looks fine , can you show us how your are putting this in a RichTextBox ?
    And you no need to iterate on each servers, -ComputerName parameter of Invoke-Command
    takes array of computers do the filtering inside the scriptblock as well. Hence ,

    Invoke-Command -ComputerName $Servers.Name -ScriptBlock {
    Get-ItemProperty "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C9BC5C47-40AC-4342-BE80-1BC2B4AADFC3}"} | where-Object -FilterScript  {$_.DisplayVersion -notmatch "12.1.7445.7000" } | select PSComputerName,DisplayVersion
     
    • #113609
      cm

      Participant
      Points: 0
      Rank: Member

      I'm actually using a modified GUI, so I was putting:

      "$results = Invoke..." | Out-String

      Add-RichTextBox $results

      I'm sure that's completely wrong.

  • #113690

    Participant
    Points: 20
    Rank: Member

    "$results = Invoke..." is the problem here, anything between quotes are treated as string.
    You can capture the output in a variable and use the variable further, for example,

    
    $Results = Invoke-Command -ComputerName $servers -Scriptblock { # your code }
    $TextBox.Text = $Results | Out-String
    
    • #114376
      cm

      Participant
      Points: 0
      Rank: Member

      Hello.

      This is driving me nuts.

      How do I get this to display to a richtextbox?

      Foreach ($server in $servers)

      {

      Invoke-command -ComputerName $Server.Name -ScriptBlock {Get-ItemProperty "..."} | Select PSComputerName, DisplayVersion | where {$_.DisplayName -Match "Software" } | Out-String

      }

You must be logged in to reply to this topic.