Select-String not working in winpe powershell 4 but OK on win7

125 views Asked by At

The following code will not work in winpe running PS 4 but will on 7...

$handler_Find_Click= 
{
$textbox1.Items.Clear();

Select-String -AllMatches -Path "x:\Scripts\PowerShell\Hosp.txt" -pattern ($HospInput.Text) | Select-Object -expand line | ForEach-Object {$textbox1.Items.Add($_)}
}

if i click the form button in win7 it shows the matched contents of the file in a textbox. In winpe it shows nothing on button click - but gives no errors.

SOLVED

The input box is not being recognized as i write-host the $Hospinput value when the form closes and its always this in winpe

System.Windows.Forms.TextBox, Text:

but not in win7

i have actually solved it. it was this.

i have another submit button in the code which worked fine on click - to close the form etc.

this submit button calls like so :

$button.add_click({ do something here }) 

the search button was calling a variable which had the execute code in like this..

$find.add_click($handler_Find_Click)

Then i had

$handler_find_click={ do something here }

winpe does not like calling a variable to execute on click - as soon as i changed to this - it worked - so removing the $handler_find_click variable altogether.

$find.add_click({ do something here })
0

There are 0 answers