Last active
October 1, 2019 01:50
-
-
Save CannoHarito/e12354f9e6e6e2ebf161623b33c8c8d7 to your computer and use it in GitHub Desktop.
指定時刻まで待つpowershell
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
function Start-Wait-Ui() { | |
param( | |
[Parameter(ValueFromPipeline = $true)] | |
[DateTime]$enddate = (Get-Date).AddMinutes(30) | |
) | |
$rawui = $Host.ui.rawui | |
while ( ($remain = $enddate - (get-date)) -ge 0) { | |
while ($rawui.KeyAvailable) { | |
switch ($rawui.Readkey("NoEcho,IncludeKeyUp").Character) { | |
'y' { return } | |
} | |
} | |
Write-Progress -Activity "Waiting..." -Status "For $enddate, or Press Y to continue right now" -SecondsRemaining $remain.TotalSeconds | |
Start-Sleep -Seconds 1 | |
} | |
} | |
#(Get-Date).AddMinutes(10)|Start-Wait-Ui |
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
function Start-Wait-Ui() { | |
[CmdletBinding(DefaultParameterSetName = "Set1")] | |
param( | |
[Parameter(ValueFromPipeline = $true, ParameterSetName = "Set1")] | |
[DateTime]$enddate = (Get-Date).AddMinutes(30), | |
[Parameter(Position = 0, ValueFromPipeline = $true, ParameterSetName = "Set2")] | |
[Int] | |
$Seconds = 0, | |
[Parameter(ParameterSetName = "Set2")] | |
[Int] | |
$Milliseconds = 0 | |
) | |
if ($PSCmdlet.ParameterSetName.Equals("Set2")) { | |
$enddate = (Get-Date).AddSeconds($Seconds).AddMilliseconds($Milliseconds) | |
} | |
$rawui = $Host.ui.rawui | |
while ( ($remain = $enddate - (get-date)) -ge 0) { | |
while ($rawui.KeyAvailable) { | |
switch ($rawui.Readkey("NoEcho,IncludeKeyUp").Character) { | |
'y' { return } | |
} | |
} | |
Write-Progress -Activity "Waiting..." -Status "For $enddate, or Press Y to continue right now" -SecondsRemaining $remain.TotalSeconds | |
Start-Sleep -Milliseconds 200 | |
} | |
} | |
#Start-Wait-Ui #30minutes | |
#(Get-Date).AddMinutes(10)|Start-Wait-Ui #10minutes | |
#Start-Wait-Ui 10 #10seconds | |
#Start-Wait-Ui -Milliseconds 500 #500milliseconds |
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
function Start-Wait() { | |
param( | |
[Parameter(ValueFromPipeline = $true)] | |
[DateTime]$enddate = (Get-Date).AddMinutes(30) | |
) | |
while ( ($remain = $enddate - (get-date)) -ge 0) { | |
Write-Progress -Activity "Waiting..." -Status "For $enddate" -SecondsRemaining $remain.TotalSeconds; | |
Start-Sleep -Seconds 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment