我正在解析一个配置任务,我需要获取所有没有“失败电子邮件”部分的任务。下面是来自任务 xml 的部分。
<Settings>
<Tasks>
<Task ID="916360623" Name="name1" Active="0" NextEID="21" CacheNames="random">
<Schedules/>
<NextActions>
<NextAction DoIfSuccess="1" DoIfFailure="0" DoIfNoAction="0" DoAfter="Task" Type="Task" TaskID="545310265"/>
<NextAction DoIfSuccess="0" DoIfFailure="1" DoIfNoAction="0" DoAfter="Task" Type="Email" HostID="385322183" AddressTo="email1@email.com, email2@email.com" Subject="[TaskName] - [TaskStatus]" Message="emailMessageFail"/>
<NextAction DoIfSuccess="1" DoIfFailure="0" DoIfNoAction="0" DoAfter="Task" Type="Email" HostID="385322183" AddressTo="email1@email.com, email2@email.com" Subject="[TaskName] - [TaskStatus]" Message="emailMessageSuccess"/>
</NextActions>
</Task>
<Task ID="701754236" Name="Task2" Active="0" NextEID="21" CacheNames="random">
<NextActions>
<NextAction DoIfSuccess="1" DoIfFailure="0" DoIfNoAction="0" DoAfter="Task" Type="Task" TaskID="840519929"/>
<NextAction DoIfSuccess="0" DoIfFailure="1" DoIfNoAction="0" DoAfter="Task" Type="Email" HostID="385322183" AddressTo="email1@email.com, email2@email.com" Subject="[TaskName] - [TaskStatus]" Message="emailMessage"/>
</NextActions>
</Task>
</Tasks>
</Settings>
我有一个 powershell 脚本,可以循环执行每个任务,<NextAction>
但是每个任务似乎并没有成功地只完成我想要的任务。获得没有DoIfFailue="1"
AND的任务报告的最佳方法是Type="Email"
什么?
set-executionpolicy unrestricted
[xml]$config = Get-Content c:\path\config.xml
$allTasks = @()
foreach($task in $config.Settings.Tasks.task){
$taskID = $task.name
foreach($nextAction in $task.NextActions.NextAction){
if(($nextAction.DoIfFailure = "1") -AND ($nextAction.type = "Email")){
$address = $nextAction.addressto
$subject = $nextAction.subject
$message = $nextAction.message
$allTasks += @(New-Object -TypeName psobject -Property @{'ID' = $taskID; 'emailAddress' = $address; 'emailSubject' = $subject; 'emailMessage' = $message})
}
}
}
$allTasks | Export-Csv -Path c:\path\output.csv -notype