# Restart Computer -email using powershell

**URL:** <https://forums.powershell.org/t/restart-computer-email-using-powershell/12372>\
**Category:** PowerShell Help\
**Created:** [April 10, 2019, 7:33am UTC](https://forums.powershell.org/t/restart-computer-email-using-powershell/12372 "2019-04-10T07:33:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gval](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@gval](https://forums.powershell.org/u/gval)\
**Post date:** [April 10, 2019, 7:33am UTC](https://forums.powershell.org/t/restart-computer-email-using-powershell/12372/1 "2019-04-10T07:33:48Z")

</div>

I would like to restart the server using powershell and also want to know whether or not the reboot was successful.

I have created the powershell script:

```
Restart-Computer -ComputerName Qyhz –Force -ErrorVariable status

if ($status.fullyqualifiederrorid -like "*Failed*")

{

Write-Log -Message 'server restart failed.' -Path c:\temp\test.log

}

else

{

Write-Log -Message 'server restart succeeded.' -Path c:\temp\test.log

}

send -mailmessage -from operating.system@abc.com -To asdf@abc.com -subject test -attachment 'c:\Temp|test.log' -smtp server "127.0.0.1"
```

Can any one suggest me how to send a status email?

---

<div class="post-metadata">

**Author:** ![pwshliquori](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/pwshliquori/32/222_2.png) [@pwshliquori](https://forums.powershell.org/u/pwshliquori)\
**Post date:** [April 10, 2019, 8:07am UTC](https://forums.powershell.org/t/restart-computer-email-using-powershell/12372/2 "2019-04-10T08:07:50Z")

</div>

In this case, Try/Catch/Finally may work for you. In your Restart-Computer command, instead of the `-ErrorVariable` parameter, use `-ErrorAction Stop` to catch the error and email it.

pwshliquori

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [April 10, 2019, 10:17pm UTC](https://forums.powershell.org/t/restart-computer-email-using-powershell/12372/3 "2019-04-10T22:17:04Z")

</div>

You will only know if the reboot is successful, after the machine restarts. This script would not be in play on a reboot, so there is nothing to get from it.

You need a scheduled task to fire on startup and send the email. No real reason to write to or read a log file.

---

<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:33pm UTC](https://forums.powershell.org/t/restart-computer-email-using-powershell/12372/4 "2024-05-16T20:33:02Z")

</div>


