The confirm.ps1
is a wrapper script so that any other program can be wrapped into getting user confirmation before it is run. My use case is that I have disabled MS Windows Server system reboot or shutdown in the Start
menu so that Administrators do not kill the production server by mistake when logging out. Nonetheless they are provided a desktop shortcut to reboot the server if really needed.
Last active
April 1, 2017 14:41
-
-
Save didenko/af33971bfa513f07a01c5fbc323a44e6 to your computer and use it in GitHub Desktop.
Confirmation PowerShell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$command = $args[0] | |
$title = "Please, confirm:" | |
$message = "Would you like to execute the " + $command + "?" | |
$yes = New-Object ` | |
System.Management.Automation.Host.ChoiceDescription ` | |
" &Yes ", ` | |
$( "Runs the command: " + $args ) | |
$no = New-Object ` | |
System.Management.Automation.Host.ChoiceDescription ` | |
" &No ", ` | |
"Aborts the action." | |
$options = [System.Management.Automation.Host.ChoiceDescription[]]( $yes, $no ) | |
$result = $host.ui.PromptForChoice( $title, $message, $options, 1 ) | |
switch ($result) | |
{ | |
0 { $("" + $args) | Invoke-Expression } | |
1 {"Cancelled the command: " + $args } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
powershell.exe -nologo -command "&" C:\bin\confirm.ps1 shutdown /r /t 15 /f /d p:0:0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment