I have one script in which I am creating a hashtable to fetch account details from 3 active directory groups. It worked fine and when i called the $hash .. I am getting exact output. However, when I tried to put the same output in event log msg.. the log msg looked like this
System.Collections.Specialized.OrderedDictionary
$hash = [ordered]@{
Enterpriseadmin = get-adgroup -filter * -searchbase 'cn=enterprise Admins,cn=users,dc=abc,dc=net' -properties name, members | select name, @{n=’Members’; e= { ( $_.members | % { (Get-ADObject $_).Name }) -join “,” }} | Sort-Object -Property Name
Schemaadmin = get-adgroup -filter * -searchbase 'cn=schema Admins,cn=users,dc=abc,dc=net' -properties name, members | select name, @{n=’Members’; e= { ( $_.members | % { (Get-ADObject $_).Name }) -join “,” }} | Sort-Object -Property Name
DomainAdmin = get-adgroup -filter * -searchbase 'cn=domain Admins,cn=users,dc=abc,dc=net' -properties name, members | select name, @{n=’Members’; e= { ( $_.members | % { (Get-ADObject $_).Name }) -join “,” }} | Sort-Object -Property Name
}
i tried to save the hashtable output to a variable and then use it in msg like $msg = $hash but same output on eventlog message.
New-eventlog -logname Application -Source "ascript"
Write-EventLog -LogName "Application" -Source "aScript" -EventId 123 -EntryType Information -Message $hash
Am I missing something here? How to convert this message into output?
Thanks. i have figured out how to post the output to eventlog message $body = $hash.getenumerator() | Format-table | out-string Then, by just putting $body after -message in write-eventlog command.. it logs the output to event log message.