我正在尝试在任务计划程序中运行ps1文件。 该任务应该每天晚上运行,历史记录表明它已经运行,
但这并不是真的,因为我可以在SonarQube中看到它没有。
每个步骤都可以按预期工作,如果我运行操作并命令一切正常,则一切正常:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\sonarqube\run_sonar_scan.ps1
我还尝试使用完整的Powershell路径
任务:
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2020-07-27T13:10:30.3806911</Date>
<Author>xxx\yyy</Author>
<Description>Starts the SonarScanner bat files from run_sonar_scan.ps1</Description>
<URI>\DdDRetail\SonarScanner</URI>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2020-07-27T21:00:00</StartBoundary>
<ExecutionTimeLimit>PT4H</ExecutionTimeLimit>
<Enabled>true</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-18</UserId>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>false</AllowHardTerminate>
<StartWhenAvailable>true</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<WakeToRun>true</WakeToRun>
<ExecutionTimeLimit>PT8H</ExecutionTimeLimit>
<Priority>7</Priority>
<RestartOnFailure>
<Interval>PT1M</Interval>
<Count>3</Count>
</RestartOnFailure>
</Settings>
<Actions Context="Author">
<Exec>
<Command>powershell.exe</Command>
<Arguments>-NoProfile -ExecutionPolicy Bypass -File "C:\sonarqube\run_sonar_scan.ps1"</Arguments>
</Exec>
</Actions>
</Task>
ps1文件:
$repo_file_path="C:\Users\xxx\source\repos"
Start-Process "cmd.exe" "/c $repo_file_path\run_articleservice_scan.bat"
蝙蝠文件
答案 0 :(得分:1)
无论用户是否登录,用户都必须是管理员或具有运行权限。用户已更改为管理员,一切正常,任务已按预期执行。