this is my code
write-eventlog -computername $env:COMPUTERNAME -logname Application -source ShmeibarCheck -eventID 32 -message “Check Status of $Object.Server Status $Object.PortOpen”
and the event-log look like this
Check Status of @{Server=192.168.1.1;
How can I remove the hash and get my prop in the string ?
Hello Itamar,
Option 1: Tell PowerShell you want $Object.Server or $Object.PortOpen to be evaluated inside the string using the $( any expression which can be evaluated or executed ) syntax.
Write-Eventlog -ComputerName $env:COMPUTERNAME -LogName Application -Source ShmeibarCheck -EventId 32 -Message "Check Status of $( $Object.Server ) Status $( $Object.PortOpen )"
Option 2: Use Composite Formatting (TinyURL.com - shorten that long URL into a tiny URL) which I usually prefer because the string can be saved in external files, databases, etc.
Write-Eventlog -ComputerName $env:COMPUTERNAME -LogName Application -Source ShmeibarCheck -EventId 32 -Message ("Check Status of {0} Status {1}" -f $Object.Server, $Object.PortOpen)
Best,
Daniel
You can loop through the elements of the $Object.Server array and write them individually to the log. That would post several event-32s in the log.
Alternatively, you can create a temp string variable and concatenate the $Object.Server array elements into it, and use it in your write-eventlog statement. Something like:
$Temp = $null; ForEach ($Item in $Object.Server) {$Temp += [string]$Item + " -"}
write-eventlog -computername $env:COMPUTERNAME -logname Application -source esent -eventID 103 -message "Check Status of $Temp Status $Object.PortOpen"
Can you post printout of how your $Object looks like?
Type in
$Object | Select *
and post the output here please…
Daniel Krebs - Tnx
this is what I’m looking
Tnx
Itamar