r/PowerShell • • Feb 02 '23

Question Powershell script to shutdown a computer

Hi, I could use your help. I am trying to create a Powershell script that allows me to shutdown a computer after 10 minutes. Once I run the script I wanted a window to pop up telling the user that the computer would shut down in 10 minutes, and if he wanted to cancel. If he hit the cancel button the script would stop, if he didn't touch the computer after 10 minutes it would shutdown. Can you help me create a script like this? Thanks.

0 Upvotes

28 comments sorted by

View all comments

0

u/[deleted] Feb 02 '23

[deleted]

1

u/MrInkognitus Feb 03 '23

Good Morning,
Unfortunately that code is not working.
The error it gives is:

At line:9 char:231

+ ... nt(100,150) $cancel.Add_Click({ $timer.Enabled = $false $form.Close() ...

+ ~~~~~

Unexpected token '$form' in expression or statement.

At line:13 char:98

+ ... omputer will shut down in $($timer.Interval/1000) seconds" if ($timer ...

+ ~~

Unexpected token 'if' in expression or statement.

+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException

+ FullyQualifiedErrorId : UnexpectedToken

I have no programming experience, but I need a script like this at work.