0
votes

I have a powershell windows form which has a button which uses the invoke-expression to call a batch file which then calls another powershell script. the script runs fine but i do not see an output from the second script in the powershell command window.

Button which when clicked calls the second powershell script:

$run = New-Object System.Windows.Forms.Button
$run.Location = New-Object System.Drawing.Size(133,430)
$run.Size = New-Object System.Drawing.Size(75,23)
$run.Text = "Run"
$run.Add_Click({ Invoke-Expression \\$pc\c$\users\$user\desktop\a\test.bat;

 })
 [System.Windows.Forms.MessageBox]::Show("Changes Saved. Now click RUN.") })

Batch file used to call the second powershell script: c:\Windows\System32\WindowsPowerShell\v1.0\powershell -ExecutionPolicy RemoteSigned - File "C:\Users\kam\Desktop\a\Powershell.ps1"

The second script itself just copys files to a remote host, and displays output by using the write-host command. If i run this script by itself it shows the output but when i run it using an invoke expression it shows a blank powershell command window.

any help would be appreciated. Image of what is shownj when the second script runs

1

1 Answers

0
votes

Fixed, it was because i was calling the bat file to call the powershell, i just called the powershell script directly and output gets displayed.

$run = New-Object System.Windows.Forms.Button
$run.Location = New-Object System.Drawing.Size(133,430)
$run.Size = New-Object System.Drawing.Size(75,23)
$run.Text = "Run"
$run.Add_Click({ Invoke-Expression \\$pc\c$\users\$user\desktop\a\powershell.ps1;

 })
 [System.Windows.Forms.MessageBox]::Show("Changes Saved. Now click RUN.") })