Writing Powershell script output to EventData in Event log

Hi all. I’m fairly new to Powershell scripting, and became stumped on this task based on experience & research. Any help would be greatly appreciated! Please see below.

Objective: Output the results of Name, OperatingSystem, OperatingSystemVersion, lastlogondate to an event log. Currently and reasonably, it’s only outputting the message “This is a test” below in the event log. Any suggestions of how to output the results of the script itself to the event log it generates?

`

cd c:\scripts

Get-ADComputer -Filter * -Property * | Select-Object -Property Name,OperatingSystem,OperatingSystemVersion,lastlogondate

Write-EventLog -LogName Application -EventID 3000 -EntryType Information -Source ‘AD PC OS Information’ -Message ‘This is a test’
cd c:\scripts

$props = 'Name','OperatingSystem','OperatingSystemVersion','LastLogonDate'

$Info = Get-ADComputer -Filter * -Property $props | Select-Object -Property $props

$template = @"
{0} : {1}

{2} : {3}

{4} : {5}

{6} : {7}
"@

$info | ForEach-Object {
    $str = $template -f $($_.psobject.Properties | ForEach-Object {$_.name,$_.value})
    Write-EventLog -LogName Application -EventID 3000 -EntryType Information -Source ‘AD PC OS Information’ -Message $str
}

This is perfect, thanks Doug!

@Doug Nice script!

Lol thanks @Rob it was the only way I could make it look nice with varying value lengths