Sending notification before shutting down a computer is a
good practice and show kindness to users.
It will give time for the user to save whatever data that needs
saving.
But of course, you can always shutdown even without notice. This
could be unfair to the users.
So exercise power with caution and responsibility, Karma is
always around. It never fades away.
The code snippet from Technet Scripting guy on the link below
shows how to use PowerShell to display a pop-up Window.
It's better to use a pop-window than a balloon notification
which user might not notice.
Using the cool Shell of PowerShell, code below will display
notification before restarting the computer.
It uses the sleep command, which can also be used on batch
file.
Replace the "Restart-Computer" with write-host or
with a message box for testing.
Make use of PowerShell ISE, which is quite good for testing
purposes.
Here's the code:
========================================
$wshell = New-Object -ComObject Wscript.Shell
$xwshell = New-Object -ComObject Wscript.Shell
#Display pop-up box and if the user does not press
"ok" button
#Box will automatically close after 5 seconds
$wshell.Popup("This computer is scheduled for
shutdown",5,"Save your data..",0x0)
#Display pop-up box and if the user does not press
"ok" button
#Box will automatically close after 3 seconds
$xwshell.Popup("30 seconds to
shutdown",3,"Please save, you got 30 seconds..",0x0)
#wait for 30 seconds before shutting down
$xCmdString = {sleep 30}
Invoke-Command $xCmdString
Restart-Computer -ComputerName Server01
=============================================
Check out this link to shutdown or restart selected computers:
http://quickbytesstuff.blogspot.sg/2013/10/powershell-shutdown-computers.html
Enjoy; click the labels below for more PowerShell on this
blog.
Comments
Post a Comment