Powershell GUI with WPF

This topic contains 1 reply, has 1 voice, and was last updated by  Renaud 3 weeks, 3 days ago.

  • Author
    Posts
  • #103169

    Renaud
    Participant
      Hi everybody,

      I'm trying to do a GUI for a Powershell Sript.
      I'have done the GUI with Visual Studio with a WPF Template.
      The PowerShell script:

      ############# Post-Configuration Nano Server ########################################
      ############# Declaration des variables Network ########################################
      $NomNS = ""
      $IPDns = ""
      $Mask = ""
      $GW = ""
      $IPType = ""

      Add-Type -AssemblyName PresentationFrameWork, PresentationCore
      $ConfNS = @{ }
      $inputXML = Get-Content -Path "C:\Users\kris8\source\repos\ConfigurationNanoServer\ConfigurationNanoServer\MainWindow.xaml"
      $inputXMLClean = $inputXML -replace 'mc:Ignorable="d"'," -replace "x:N",'N' -replace 'x:Class=".*?"'," -replace 'd:DesignHeight="\d*?"'," -replace 'd:DesignWidth="\d*?"',"
      [xml]$xaml = $inputXMLClean
      $reader = New-Object System.Xml.XmlNodeReader $xaml
      $tempform = [Windows.Markup.XamlReader]::Load($reader)
      $NameNodes = $xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]")
      $NameNodes = $NameNodes | ForEach-Object {$ConfNS.Add($_.Name, $tempform.FindName($_.Name))}

      $ConfNS
      #Module a Importer ou Installer
      #

      ############Code Executer lors du click sur le boutton "Execute"#######################################
      ############Declaration des variables pour la configuration Network et Firewall du Nano Server#########

      $ConfNS.ConfNanoServerButton1.add_Click({

      #Declaration Nom du Nano Server
      $NomNS = $ConfNS.ConfNanoServerTextBox1.Text
      #Declaration @IP DNS
      $IPDns = $ConfNS.ConfNanoServerTextBox2.Text
      #Declaration Mask
      $Mask = $ConfNS.ConfNanoServerTextBox3.Text
      #Declaration Gateway
      $GW = $ConfNS.ConfNanoServerTextBox4.Text
      #Declaration @IP DNS
      $IPType = $ConfNS.ConfNanoServerTextBox5.Text

      })

      $ConfNS.ConfNanoServerWindows.ShowDialog() | Out-Null

      When i execute the script the Gui appears but when i click on the button normally the variable are define.
      But if i just look the content of $NomNS, there nothing.

      The goal of this script is to create another script with the good value :

      How can i keep the value i have define in the PowerShell-GUI ?
      Thx for replay.

  • #103217

    Renaud
    Participant

    is it possible to delete this post please, my error.

    Thx and so sorry ...

You must be logged in to reply to this topic.