2

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

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Amiga1200
  • 91
  • 7

0 Answers0