【发布时间】:2016-10-17 10:11:11
【问题描述】:
我正在尝试通过任务计划程序运行此 PowerShell 代码,因为我想 24*7 运行此代码。任务计划程序未在 .ps1 文件中运行。所以我想从任务计划程序运行一个 .bat 文件,它会调用这个 PowerShell 文件。
以下是我的 PowerShell 代码(文件名为 Watch.ps1):
### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "D:\MigrationWorkflow\UAT"
$watcher.EnableRaisingEvents = $true
### DEFINE ACTIONS AFTER A EVENT IS DETECTED
$action = { $path = $Event.SourceEventArgs.FullPath
$changeType = $Event.SourceEventArgs.ChangeType
$logline = "$(Get-Date), $changeType, $path"
Invoke-Expression 'MASysMgr.exe -w MigrationUAT.smw -f "D:\MigrationWorkflow\UAT\ParameterUat.smp" -l WorkflowResults.log -showoutput' }
### DECIDE WHICH EVENTS SHOULD BE WATCHED + SET CHECK FREQUENCY
$created = Register-ObjectEvent $watcher "Created" -Action $action
while ($true) {sleep 0}
【问题讨论】:
标签: powershell scheduled-tasks