# Write-Eventlog source name missing

**URL:** https://forums.powershell.org/t/write-eventlog-source-name-missing/13880
**Category:** PowerShell Help
**Created:** [February 27, 2020, 3:48pm UTC](https://forums.powershell.org/t/write-eventlog-source-name-missing/13880 "2020-02-27T15:48:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![trgrassijr](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@trgrassijr](https://forums.powershell.org/u/trgrassijr)
#### Post date: [February 27, 2020, 3:48pm UTC](https://forums.powershell.org/t/write-eventlog-source-name-missing/13880/1 "2020-02-27T15:48:43Z")

</div>

Wrote a small script to write to my System Event Log and restart my servers

```auto
$Server = hostname
New-Eventlog -logname System -source "System Restart"
Write-EventLog -Logname System -source " System Restart" -EntryType Information -EventId 99 -Message "System Restart for Security updates."

```

Write-EventLog : The source name " System Restart" does not exist on computer “localhost”.  
At line:1 char:1

- Write-EventLog -Logname System -source " System Restart" -EntryType I …
- 

```auto

```

- CategoryInfo : InvalidOperation: (🙂 [Write-EventLog], InvalidOperationException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteEventLogCommand

I ran this command

[system.diagnostics.eventlog]::SourceExists(“System Restart”)  
True

&nbsp;

&nbsp;

Any Ideas?

&nbsp;

Thank you

Tom

---

<div class="post-metadata">

### Author: ![gnart](https://avatars.discourse-cdn.com/v4/letter/g/5e9695/32.png) [@gnart](https://forums.powershell.org/u/gnart)
#### Post date: [February 27, 2020, 4:17pm UTC](https://forums.powershell.org/t/write-eventlog-source-name-missing/13880/2 "2020-02-27T16:17:55Z")

</div>

Hi Tom,

I saw a couple of errors, after fixing I tested and it worked.  
1st. The codes as posted used smart quotes (as in MS-Word quotes). Change them to straight double-quotes or single-quote.  
2nd. You have a leading space " System Restart" in the Write-EventLog

`$Server = hostname
New-Eventlog -logname System -source “System Restart”
Write-EventLog -Logname System -source “System Restart” -EntryType Information -EventId 99 -Message “System Restart for Security updates.”`

---

<div class="post-metadata">

### Author: ![trgrassijr](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@trgrassijr](https://forums.powershell.org/u/trgrassijr)
#### Post date: [February 27, 2020, 4:25pm UTC](https://forums.powershell.org/t/write-eventlog-source-name-missing/13880/3 "2020-02-27T16:25:33Z")

</div>

Hi GNART

OMG a little space in the wrong place.

Thanks for the quick response.

&nbsp;

Tom

&nbsp;

&nbsp;

---

<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:30pm UTC](https://forums.powershell.org/t/write-eventlog-source-name-missing/13880/4 "2024-05-16T20:30:39Z")

</div>


