'In can't use my variable in a powershell command for a GUI in Powershell Studio

i'm a bit noobie in powershell and i'm trying to build a simple user interface in Powershell Studio 2018 to search for a list of user named like in an active direction. Out of the Powershell Studio it works very fine but inside PSS2018 i can't use a variable in my command ...

My goal is simply to output my results in a listbox

#$gui_searchUser01.text is well returned on my mouse click event so i transform it into
 '*nameentered*'

    $searchstringADname = " '*" + $gui_searchUser01.Text + "*'"

    # If i do 
#Get-ADUser -Filter { name -like '*nameentered*' } -Properties name | Select-Object Name 
#it's outputing well in texbox1 but not working will the next line :(

    $ADusers = Get-ADUser -Filter { name -like " '*" + $gui_searchUser01.Text + "*'" } -Properties name | Select-Object Name

    $textbox1.Text = $ADusers

    #$gui_UsersResults01.Items.AddRange([System.Collections.ArrayList]$ADusers)**

I also tried of course to put directly $searchstringADname in my command with the same results, not working for the gui but working well in classic powershell


Another try which is not working :(

$button1_Click={
    #TODO: Place custom script here
    [string]$getvalue = $textbox1.Text
    [string]$searchstringADname = " '*" + $getvalue + "*'"
    [string]$results = Get-ADUser -Filter { name -like $searchstringADname } -Properties name | Select-Object Name
    $textbox2.Text = $results
}

$searchstringADname is not returned into the command it stay "null" but when i write-host into the textbox2 directly i got my value ! $searchstringADname ! i will kill myself lol



Solution 1:[1]

Something that work for me is: Delete your pubspec.lock, and press Pub Get in your pubspec.yaml, it'll regenerate pubspec.lock file again and should fix the problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anmol Mishra