# PsObject in a String

**URL:** <https://forums.powershell.org/t/psobject-in-a-string/2854>\
**Category:** PowerShell Help\
**Created:** [July 19, 2014, 3:41pm UTC](https://forums.powershell.org/t/psobject-in-a-string/2854 "2014-07-19T15:41:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![itamar-tziger](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/itamar-tziger/32/806_2.png) [@itamar-tziger](https://forums.powershell.org/u/itamar-tziger)\
**Post date:** [July 19, 2014, 3:41pm UTC](https://forums.powershell.org/t/psobject-in-a-string/2854/1 "2014-07-19T15:41:25Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![daniel-krebs](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/daniel-krebs/32/484_2.png) [@daniel-krebs](https://forums.powershell.org/u/daniel-krebs)\
**Post date:** [July 19, 2014, 8:49pm UTC](https://forums.powershell.org/t/psobject-in-a-string/2854/2 "2014-07-19T20:49:59Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![sam-boutros](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/sam-boutros/32/5_2.png) [@sam-boutros](https://forums.powershell.org/u/sam-boutros)\
**Post date:** [July 19, 2014, 9:12pm UTC](https://forums.powershell.org/t/psobject-in-a-string/2854/3 "2014-07-19T21:12:05Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![itamar-tziger](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/itamar-tziger/32/806_2.png) [@itamar-tziger](https://forums.powershell.org/u/itamar-tziger)\
**Post date:** [July 19, 2014, 9:18pm UTC](https://forums.powershell.org/t/psobject-in-a-string/2854/4 "2014-07-19T21:18:54Z")

</div>

Daniel Krebs - Tnx  
this is what I’m looking

Tnx  
Itamar

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:47pm UTC](https://forums.powershell.org/t/psobject-in-a-string/2854/5 "2024-05-16T20:47:45Z")

</div>


