Reputation: 37
I want to run a shutdown command on a remote computer, but I want the user to be prompted to accept or decline the command. This is what I have. It prompts the local user for the $computername, I need to run an input prompt on the remote computer user, then execute the shutdown script.
$server=read-host 'Enter Name'
$choice = ""
while ($choice -notmatch "[y|n]"){
$choice = read-host "Do you want to continue? (Y/N)"
}
if($choice -eq "y"){
shutdown /m \\$server /r /t 00
}
else {write-host "Please contact your systems administrator."}
Upvotes: 0
Views: 1563
Reputation: 13483
The biggest problem is displaying the message to the user because it has to run interactively in that user session.
One method, if you just want to display a message that the computer is about to shutdown, and you don't want them to be able to cancel, would be to leverage the remote shutdown command:
shutdown -m //computername -r -f -c "MESSAGE" -t 120
If you need more comprehensive shutdown, where the user can always cancel (and believe me, they will always choose to cancel) the shutdown, then you need to use something like PsExec where you run a script in the interactive session:
psexec.exe \\computername -I message.vbs
Where message.vbs could be whatever more complex script (or PowerShell script) that you need to run.
Upvotes: 1