Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Afternoon,

I need to utilize the AWS s3 ls command and have it automatically output to the textbox, instead of being required to execute on button push. How can I make this happen?

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")  

$Form = New-Object System.Windows.Forms.Form    
$Form.Size = New-Object System.Drawing.Size(600,400)  

############################################## Start functions

function s3Info {
$s3Result= aws s3 ls | fl | out-string;
$outputBox.text=$s3Result
                     } #end s3Info

############################################## end functions


############################################## Start text fields


$outputBox = New-Object System.Windows.Forms.TextBox 
$outputBox.Location = New-Object System.Drawing.Size(10,150) 
$outputBox.Size = New-Object System.Drawing.Size(565,200) 
$outputBox.MultiLine = $True 
$outputBox.ScrollBars = "Vertical" 
$Form.Controls.Add($outputBox) 

############################################## end text fields

############################################## Start buttons

$Button = New-Object System.Windows.Forms.Button 
$Button.Location = New-Object System.Drawing.Size(400,30) 
$Button.Size = New-Object System.Drawing.Size(110,80) 
$Button.Text = "Ping" 
$Button.Add_Click({s3Info}) 
$Form.Controls.Add($Button) 

############################################## end buttons

$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()


What I have tried:

I have tried to remove the function and add just an out-string to outputBox.text with no positive results.
Posted
Updated 11-May-17 9:04am
Comments
Richard Deeming 4-May-17 12:46pm    
How about:
$Form.Add_Load({s3Info})
[no name] 4-May-17 12:52pm    
Under which section? Do you mean remove to button information and use $Form.Add_Load{s3Info})?
Richard Deeming 4-May-17 12:56pm    
Just under the $Form.Add_Shown(...) line. If it works, you should be able to remove the $Button lines.
[no name] 5-May-17 7:33am    
Would I need to add Multiple $Form.add_Loads if I add multiple text boxes and functions to call to fill said boxes?
Richard Deeming 5-May-17 9:15am    
That would probably be the best approach.

1 solution

Had to use a split in
3Result=ping $S3Path $Local 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900