WPF Application - Script within add_click Event doesn't work

Welcome Forums General PowerShell Q&A WPF Application - Script within add_click Event doesn't work

Viewing 1 reply thread
  • Author
    Posts
    • #44103
      Participant
      Topics: 1
      Replies: 0
      Points: 0
      Rank: Member

      Hi,

      I've created an XML Dialog Window with a button and added the add_click Event to the script:
      `
      $WPFbuttonPreviewGroup.add_Click({

      #Write-Host "Previewing group"
      $param1 = "`$_." + $WPFComboField1.SelectedValue + " " + $WPFComboBool1.SelectedValue + " " + '"' + $WPFtextValue1.Text + '"'
      $MsolUserList = Import-Csv "allMsolUser.csv" -Delimiter ";"
      $MsolUserList | ft
      $commandstring = '$msolUserList | ?{' + $param1 + '}'
      $x = Invoke-Expression $commandstring -Verbose
      })`

      When I run the script above manually from ISE, it work fine.
      But when I call the dialog box and pressing the button to fire the event, the script doesn't import the csv file.
      All other command within this script work fine (e.g. $param1 = ....)

    • #44707
      Keymaster
      Topics: 13
      Replies: 4872
      Points: 1,844
      Helping HandTeam Member
      Rank: Community Hero

      So, I'll assume you're already aware of the serious negative security implications of Invoke-Expression, and no go into that ;).

      Have you tried using a fully-qualified file path for the CSV? As-is, you're loading it from "the current directory," which may not be what you think it is, when this runs as a WPF. Obviously, since the ISE sets the current directory, it's working there.

Viewing 1 reply thread
  • The topic ‘WPF Application - Script within add_click Event doesn't work’ is closed to new replies.