when calling a script inside a script, tables are not shown RRS feed

  • Question

  • Hi,

    i´m trying to make a graphical toolbox for my own and/or downloaded scripts.

    In this part i call another script named "Speicherabfrage.ps1". (Downloaded script to read RAM Informations)

    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

    $objForm = New-Object System.Windows.Forms.Form


    $Raminfo_PS = New-Object System.Windows.Forms.Button
    $Raminfo_PS.Location = New-Object System.Drawing.Size(100,180)
    $Raminfo_PS.Size = New-Object System.Drawing.Size(80,23)
    $Raminfo_PS.Text = "Raminfo_PS"
    $Raminfo_PS.Name = "Raminfo_PS"


    [void] $objForm.ShowDialog()

    the called script start like this:

        [string]$Computername = "localhost"
    $PysicalMemory = Get-WmiObject -class "win32_physicalmemory" -namespace "root\CIMV2" -ComputerName $Computername
    Write-Host "Memory Modules:" -ForegroundColor Green
    $PysicalMemory | Format-Table Tag,BankLabel,@{n="Capacity(GB)";e={$_.Capacity/1GB}},Manufacturer,PartNumber,Speed -AutoSize
    Write-Host "Total Memory:" -ForegroundColor Green
    Write-Host "$((($PysicalMemory).Capacity | Measure-Object -Sum).Sum/1GB)GB"


    the complete script is postet correctly except the table and no errors are displayed. Do i have to convert the table? Should i call the script in another way? Any Ideas why tables are not shown?

    • Edited by ALaue Tuesday, June 2, 2020 11:42 AM
    Tuesday, June 2, 2020 10:14 AM

All replies

  • You cannot display output from a form.  The form will block the output.  Only the Write-Host statements will be displayed a they are console specific.

    Search for articles on how to work with forms in PowerShell.  The articles will help you to understand how forms work and how to use them with PowerShell.


    Tuesday, June 2, 2020 3:56 PM
  • Thanks for this Information. I will have a look at forms and how to use them. 

    Perhaps u can help me if i want to try to display it in another window like this:

    $Raminfo = New-Object System.Windows.Forms.Button
    $Raminfo.Location = New-Object System.Drawing.Size(100,150)
    $Raminfo.Size = New-Object System.Drawing.Size(75,23)
    $Raminfo.Text = "Raminfo"
    $Raminfo.Name = "Raminfo"
        $PysicalMemory = Get-WmiObject -class "win32_physicalmemory" -namespace "root\CIMV2" -ComputerName localhost
        $PysicalMemorytag  = $PysicalMemory | select * -ExpandProperty Tag
        $PysicalMemoryBankLabel = $PysicalMemory | select * -ExpandProperty Banklabel
        $PysicalMemoryCap = $PysicalMemory | ft @{n="Capacity(GB)";e={$_.Capacity/1GB}}
         [void] [Windows.Forms.MessageBox]::Show($PysicalMemorytag + [System.Environment]::NewLine + $PysicalMemoryBankLabel + [System.Environment]::NewLine + $PysicalMemoryCap + [System.Environment]::NewLine + $PysicalMemoryManu)
        [void] [Windows.Forms.MessageBox]::Show($PysicalMemoryCap)

    can i convert "$PhysicalMemoryCap" into a format i can use? Using the original capacity in byte will work but is there a way to display it in GB or is that impossible too?

    btw. can i mark your answer and continue writing here or is this thread closed after?
    • Edited by ALaue Wednesday, June 3, 2020 9:46 AM
    Wednesday, June 3, 2020 9:43 AM
  • Hi,
    Was your issue resolved? 
    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.
    Best Regards,
    Yang Yang

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, July 3, 2020 3:27 AM