Adapted Lazyadmin tool does not recognize button

Welcome Forums General PowerShell Q&A Adapted Lazyadmin tool does not recognize button

Viewing 3 reply threads
  • Author
    Posts
    • #194105
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      Hello All,

      New to forum, tried search option but unable to find the question.

       

      i Am having some troubles adapting a button in the well known lazy admin tool.

      I am able to do the rest (adding scripts, adding or removing options.

      No issues with this.

       

      The specific code that i have some issues with is the following:

      One of the buttons has been ajusted to retrive build number.

      However i am able to execud code individual, but not in combination.

      $button_remot_Click={
      Get-ComputerTxtBox
      Add-logs -text "Show windows build version for $ComputerName"
      $OSWin32_OS = Get-WmiObject -Class Win32_OperatingSystem $ComputerName
      if ($result -ne $null)
      {
      if ($result.ReturnValue -eq 0){
      Show-MsgBox -BoxType "OKOnly" -Title "$ComputerName – OS version" -Prompt "Win version shown successfully!" -Icon "Information"
      Add-RichTextBox $($result|Out-String)
      }
      }
      else {Show-MsgBox -BoxType "OKOnly" -Title "$ComputerName – OS version " -Prompt "Win Version does not work!" -Icon "Exclamation"}
      }

       

      At $OSWin32 i have 

      $OSWin32_OS = Get-WmiObject -Class Win32_OperatingSystem -Namespace "root\cimv2" -ComputerName $ComputerName

       

      Using $OSWin32 and $ComputerName are working individual (tested in Powershell ISE).

      The code provide the correct output (splash screenwith error message because it does not read the command:

       

      $OSWin32_OS = Get-WmiObject -Class Win32_OperatingSystem $ComputerName

       

      Output when testing individual:

       

      PS C:\> Get-WmiObject -Class Win32_OperatingSystem

      SystemDirectory : C:\Windows\system32
      Organization :
      BuildNumber : 1809
      RegisteredUser : Windows User
      SerialNumber : ****-****-****-****
      Version :*.*.****

      PS C:\> $OSWin32_OS = Get-WmiObject -Class Win32_OperatingSystem $ComputerName
      Get-WmiObject : Value cannot be null.
      Parameter name: value
      At line:1 char:16
      + $OSWin32_OS = Get-WmiObject -Class Win32_OperatingSystem $ComputerName
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [Get-WmiObject], ArgumentNullException
      + FullyQualifiedErrorId : System.ArgumentNullException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

      PS C:\>

       

      So, this show me at least that the individual inputs are working, but in conjunction they do not.

      The idea is to press a button, and that provides above information.

      What can i do to get it to work? it shows the error message, i know that the error is in the in red highlighted bit.

      the rest works ok.

       

      thank you for pointing me to the correct location.

    • #194159
      Participant
      Topics: 10
      Replies: 1381
      Points: 1,509
      Helping Hand
      Rank: Community Hero

      At $OSWin32 i have 

      $OSWin32_OS = Get-WmiObject -Class Win32_OperatingSystem -Namespace "root\cimv2" -ComputerName $ComputerName

      The first thing I would try is using a strongly-type command. The above command is strongly typed, but this is not:

      $OSWin32_OS = Get-WmiObject -Class Win32_OperatingSystem $ComputerName
      

      The $ComputerName variable is passed but you are not specifying the parameter as qouted initially. Next thing is the $Computername variable isn't set in the code you posted, so you should change the code to look like this:

      $button_remot_Click={
      $ComputerName = Get-ComputerTxtBox
      Add-logs -text "Show windows build version for $ComputerName"
      $OSWin32_OS = Get-WmiObject -Class Win32_OperatingSystem -Namespace "root\cimv2" -ComputerName $ComputerName
      ...
      
    • #194402
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      thank you for the answer.

       

      Yes indeed.

      I have worked yesterday on the same, and found the missing parameters.

      Now i have output, however, the formatting of the output is not in a nice readable format.

      That will be the next part to struggle with the script.

       

      and yes, i have forgoten to show the $Computername output. it gets the variable from a input box where computername is filled in.

      The change is at the moment something like this:

       

      ` $button_remot_Click={
      Get-ComputerTxtBox
      $result = $OSWin32_OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $ComputerName |Format-Table * -AutoSize| Out-String -Width $richtextbox_output.Width
      Add-RichTextBox $result `

      The part after the |:

       

      `|Format-Table * -AutoSize| Out-String -Width $richtextbox_output.Width`

      Does work, as it puts output to the "richtextbox" however, not readable.

      When using the command indivual in powershell

      `Get-WmiObject -Class Win32_OperatingSystem -Namespace "root\cimv2" -ComputerName $ComputerName`

      Works. And shows the output nicly. This means that

      `|Format-Table * -AutoSize| Out-String -Width $richtextbox_output.Width`

      Is messing up my output.

       

      Will struggle with this part to try and get a nice output.

      have a nice day.

       

      edit:

       

      found it:

      it was the damn * that was causing this issue. lol.

      now it is nicely visible and i tables.

    • #194444
      Participant
      Topics: 10
      Replies: 1381
      Points: 1,509
      Helping Hand
      Rank: Community Hero

      Glad you figured it out. Keep in mind that 'Format-Table' is to align in the Powershell console. There are other factors such as the font used should be monospace or it will still not look right. When you are working in a GUI, you can use controls like a GridView to provide flexbility.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.