Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: PsObject in a String

$
0
0

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 (http://preview.tinyurl.com/oef3n5o) 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


Viewing all articles
Browse latest Browse all 13067

Trending Articles