Sanchit
Sanchit

Reputation: 727

(PowerShell Studio 2014 Trial) Incomplete output in textbox

I created a form using PowerShell Studio 2014 Trial with two controls i.e. a command button & a text button. Below is the code for click event on button1-

$button1_Click={

$results=Get-WinEvent -FilterHashtable @{ LogName = "application"; StartTime = "10/30/2014 12:00:01 AM"; EndTime = "10/30/2014 11:59:59 PM" }

$textbox1.Text=$results
}

When I execute this, it does not give the expected output containing logs.

It displays- "System.Diagnostics.Eventing.Reader.EventLogRecord"

Form

However, if I run-

Get-WinEvent -FilterHashtable @{ LogName = "application"; StartTime = "10/30/2014 12:00:01 AM"; EndTime = "10/30/2014 11:59:59 PM" }

on PowerShell ISE, it shows all logs.

Upvotes: 1

Views: 360

Answers (1)

Matt
Matt

Reputation: 46710

Like I said in my comment your getting the output you requested. PowerShell console handles object output with built-in cmdlets like Out-Default. You said you wanted all that information but I'm guessing you wanted what was display by default. Therefore I would make results the following

$results = Get-WinEvent -FilterHashtable @{ LogName = "application"; StartTime = "10/30/2014 12:00:01 AM"; EndTime = "10/30/2014 11:59:59 PM" } | Select provider,timecreated,id,leveldisplayname,message | Format-Table | Out-String -Width 1024

Use Select to get only what we want. Change this as you see fit. Use Format-Table to make fixed width output then pipe it into Out-String

Upvotes: 2

Related Questions