2021-05-18

用 PowerShell 判斷時間區間後執行 batch

C:\Command\Run.bat

-----------------------------------------------------------------------------------------------
C:
cd "C:\Command\"
"C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" -command ". 'C:\Command\Run.ps1';"
-----------------------------------------------------------------------------------------------

C:\Command\Run.ps1
-----------------------------------------------------------------------------------------------
$Min = Get-Date '14:00';
$Max = Get-Date '17:30';
$URL = 'https://www.google.com';

$Now = Get-Date;

if (($Min.TimeOfDay -le $Now.TimeOfDay) -and ($Max.TimeOfDay -ge $Now.TimeOfDay)) {
Start-Process -FilePath "C:\windows\system32\cmd.exe" -Wait -UseNewEnvironment;
Invoke-WebRequest -URI $URL -OutFile "URL.txt";
};
-----------------------------------------------------------------------------------------------

沒有留言:

張貼留言