WPF GUI for PowerShell Scripts

Welcome Forums General PowerShell Q&A WPF GUI for PowerShell Scripts

This topic contains 1 reply, has 2 voices, and was last updated by

2 years, 1 month ago.

  • Author
  • #67857

    Topics: 7
    Replies: 10
    Points: 0
    Rank: Member

    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.
    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 {
        DefaultParameterSetName = 'Site'
            Mandatory = $True,
            ParameterSetName = '',
            ValueFromPipeline = $True)]
            Mandatory = $True,
            ParameterSetName = '',
            ValueFromPipeline = $False)]
        #Clear the screen
        #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")
    $Window.ShowDialog() | Out-Null

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

    Please help i am actually confused.

  • #68004

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    So, this isn't "from WPF." WPF is a presentation framework, not a language.

    What language are you writing in?

The topic ‘WPF GUI for PowerShell Scripts’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort