試したらWindowsターミナルを既定のターミナルアプリケーションにしてると失敗した。 規定のターミナルアプリケーションをコンソールホストにするか、アプリ実行エイリアスでWindowsターミナルを無効にすると成功する。
仕方ないからpowershell.exeからもう一段powershellを呼び出したらWindowsターミナルになっていても成功した。
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2024-08-02T00:00:00.0000000</Date>
<Author>***\***</Author>
<URI>\test</URI>
</RegistrationInfo>
<Triggers>
<EventTrigger>
<Enabled>true</Enabled>
<Subscription><QueryList><Query Id="0" Path="Application"><Select Path="Application">*[System[Provider[@Name='Application'] and EventID=1000]]</Select></Query></QueryList></Subscription>
<ValueQueries>
<!-- イベントを発生させたユーザーのSID -->
<Value name="SID">Event/System/Security/@UserID</Value>
</ValueQueries>
</EventTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<!--Users-->
<GroupId>S-1-5-32-545</GroupId>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</Command>
<Arguments>-Command add-content -Path S:\temp2\testlog.txt (get-childitem env:\username).value</Arguments>
</Exec>
<Exec>
<Command>powershell.exe</Command>
<Arguments>-Command Start-Process -FilePath Powershell.exe -ArgumentList 'Get-Credential $(SID)'</Arguments>
<WorkingDirectory>C:\Windows\System32\WindowsPowerShell\v1.0\</WorkingDirectory>
</Exec>
</Actions>
</Task>