# WPF GUI for PowerShell Scripts

**URL:** <https://forums.powershell.org/t/wpf-gui-for-powershell-scripts/8348>\
**Category:** PowerShell Help\
**Created:** [April 4, 2017, 3:39am UTC](https://forums.powershell.org/t/wpf-gui-for-powershell-scripts/8348 "2017-04-04T03:39:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rishabh-a](https://avatars.discourse-cdn.com/v4/letter/r/f0a364/32.png) [@rishabh-a](https://forums.powershell.org/u/rishabh-a)\
**Post date:** [April 4, 2017, 3:39am UTC](https://forums.powershell.org/t/wpf-gui-for-powershell-scripts/8348/1 "2017-04-04T03:39:54Z")

</div>

How can i run powershell scripts or multiple PS Commands from WPF? I am using this thing but getting some Method invocation Error.

```
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
```

Creating runspace and calling that script. [I am calling an external script.]  
another thing i tried is :

```
using (PowerShell PowerShellInstance = PowerShell.Create())
```

But from this i can run a single command.

One working method i found was using script below:

```
Add-Type -AssemblyName PresentationFramework
[xml]$xaml = 
@"

    
        
        
        

    

"@

}
Function Test-InternetConnection {
[cmdletbinding(
    DefaultParameterSetName = 'Site'
)]
param(
    [Parameter(
        Mandatory = $True,
        ParameterSetName = '',
        ValueFromPipeline = $True)]
        [string]$Site,
    [Parameter(
        Mandatory = $True,
        ParameterSetName = '',
        ValueFromPipeline = $False)]
        [Int]$Wait
    )
    #Clear the screen
    Clear
    #Start testing the connection and continue until the connection is good.
    While (!(Test-Connection -computer $site -count 1 -quiet)) {
       # Write-Host -ForegroundColor Red -NoNewline "Connection down..."
        Write-Output "Connection down..."
        Start-Sleep -Seconds $wait
        }
    #Connection is good
    #Write-host -ForegroundColor Green "$(Get-Date): Connection up!"
     Write-Output "$(Get-Date): Connection up!"
}
Function Servicereport()
{
$obj = Get-Process | Out-GridView
Start-Sleep 2
}

Function Processreport()
{
Test-InternetConnection -Site google.com -Wait 2
Start-Sleep 2
}

$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$Window=[Windows.Markup.XamlReader]::Load( $reader )

$button1 = $Window.FindName("Services")
$button2 = $Window.FindName("Process")
$Method1=$button1.add_click
$Method2=$button2.add_click
$Method1.Invoke({Servicereport})
$Method2.Invoke({Processreport})
$Window.ShowDialog() | Out-Null
```

But with this approach i am unable to get Modern UI.

Please help i am actually confused.

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [April 5, 2017, 10:27am UTC](https://forums.powershell.org/t/wpf-gui-for-powershell-scripts/8348/2 "2017-04-05T10:27:30Z")

</div>

So, this isn’t “from WPF.” WPF is a presentation framework, not a language.

What language are you writing in?

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:38pm UTC](https://forums.powershell.org/t/wpf-gui-for-powershell-scripts/8348/3 "2024-05-16T20:38:59Z")

</div>


