Question about program setup

Hi All,

I have a question about a programm I’m creating for my collegues, the setup is as follow:

Use a .cmd file to start the main form:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -file "%WorkingDir%\Bin\LaunchConsole.ps1"

In this file I call all the functions and set some start variables:

# Set start location and include other scripts 
$ScriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$ProgramRoot = Split-Path -Path $ScriptPath -Parent

# Load all scripts
Get-ChildItem ( Join-Path ( $ScriptPath ) \Lib\ ) | Where { $_.Name -notlike '_*' -and $_.Name -notlike 'ext_*' -and $_.Name -like '*.ps1'} | ForEach { 
	#Write-Host $_.FullName #<-- Uncomment this to show / print all included files.
	. $_.FullName


# Remove leftover functions
Remove-Item function:\add*

The Form-Main is a “Windows Form” Form, a while ago I started with some experiments on WPF (Link) and would linke to create some more WPF functions and convert my pop-ups and progressbars to WPF. I’ve created a Edit Settings screen that pop-s up after clicking Options–> Settings but there are some things that are going wrong. The function that is called is View-Settings and I use a XML file to save and load settings for the app and customers:
XML Contents

The total function for the View-Settings and Edit-Settings form is uploaded here.

My question is, am I making stupid mistakes in my functions (Edit-Settings and View-Settings) The functions are not working properly, they did when they were Windows.Forms but I wanted to use the Runspaces and WPF :slight_smile: My Thoughts were to start the form in View-Settings and do something like:

$SettingsForm = EditSettings (this should return $True to save the form, $False to only close the form)
If ($SettingsForm -eq $True) { Save all XML values provided in the GUI and the DataGrid, after this, close the form }

Currently the form is started and I get some Null variable errors and the first textbox is not filled (CustomerName) If I test the source variable the value is ok… I don’t get it…

I also would like to add the progress script in my functions but how can I do this the best way.

Link to EditSettings and ViewSettings

Hope to hear, many thanks in advance and bare with me I’m a system engineer no programer :stuck_out_tongue:

Regards, Paul

Well, for better or for worse, you’re a programmer now.

Here’s the thing: that’s quite a lot of code, and I’m completely unclear what your actual problem is. You say they aren’t “working properly,” but you don’t list any error messages, describe any bad behavior, or anything else. Some detail on what the problem is might be helpful.

I’m also not clear on why you’re launching additional run spaces.

Also, keep in mind that everyone here is an administrator, not a professional programmer. If you’re having problem with the WPF code, this might not be the best place to get a real fast answer.

Hi @Don,

For readability I’ve changed the EditSettings.ps1 file:

I have two questions actualy:

  • One was If I am on the right way setting up my PowerShell application?
  • And the seccond was the mallfunction of the EditSettings Form.

Below the workflow of the app:

  • Launch App.ps1 with a .cmd file that bypasses the executionpolicy
  • App.ps1 includes all functions from bin\lib*.ps1
  • App.ps1 starts main form, FormMain.ps1
  • FormMain.ps1 contains a Windows Forms menu, all these menuitems launches seperate .ps1 files trought:
$menuOptions2.Add_Click({ . $ScriptPath\O365-EditSettings.ps1 })


$menuOptions2.Add_Click({ Invoke-Expression -command $ScriptPath\O365-EditSettings.ps1 })

Currently the file EditSettings starts, but can’t find my settings from the XML file. If I paste in the exact location of the file (no variable) it works and shows my settings. Also it it not possible to start the Folder-Browser function trough the WPF form in the runspace.

$ScriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$ProgramRoot = Split-Path -Path $ScriptPath -Parent
$XmlOffice365 = [xml](Get-Content $ProgramRoot\Edit\Customer-leokanner.xml)

In the end I would like to be able to create new XML files with settings and switch between them trough the dropdown box on top.

Thanks in advance!