我的数据看起来类似于这个问题最底部的 xml。这是数千个任务中的 3 个。有些有<DayOfWeek>
节点,有些没有。我正在努力获取这些数据并将其放入 csv 中,以便可以将其导入 sql。
我的目标是让每一天成为表格中的一列,每一行代表一个任务。如果计划在给定日期运行,则相应日期为 1,否则为 0。对于此问题底部的以下数据,表格如下所示
| taskID | mon | tue | wed | thur | fri | sat | sun |
|________|_____|_____|_____|______|_____|_____|_____|
| 1 | 1 | 0 | 0 | 1 | 1 | 1 | 0 |
| 2 | 1 | 0 | 0 | 0 | 1 | 0 | 0 |
| 3 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
我当前的 ps 脚本使这些数据更加垂直而不是水平。代码摘录
foreach($task in $config.Settings.Tasks.Task){
$taskID = $task.ID
foreach($DoW in $task.Schedules.Schedule.Days.DayOfWeek){
$newCSV += @(New-Object -TypeName psobject -Property @{'taskID' = $taskID; 'Day' = $DoW})
}
}
$newCSV | Export-Csv -Path c:\users\mhopkins\desktop\micSchedule\DoW.csv -notype
你们能帮我把这些数据在表格中更好地工作吗?
XML 片段
<Task ID="1" Name="name1" Active="1" NextEID="11">
<Schedules>
<Schedule OnlyUntilFirstSuccess="0" FailIfNoSuccessInSched="0" RunEvenIfNotif="0">
<Days>
<DayOfWeek>Monday</DayOfWeek>
<DayOfWeek>Friday</DayOfWeek>
<DayOfWeek>Thursday</DayOfWeek>
<DayOfWeek>Saturday</DayOfWeek>
</Days>
</Schedule>
</Schedules>
</Task>
<Task ID="2" Name="name2" Active="1" NextEID="12">
<Schedules>
<Schedule OnlyUntilFirstSuccess="0" FailIfNoSuccessInSched="0" RunEvenIfNotif="0">
<Days>
<DayOfWeek>Monday</DayOfWeek>
<DayOfWeek>Friday</DayOfWeek>
</Days>
</Schedule>
</Schedules>
</Task>
<Task ID="3" Name="name3" Active="0" NextEID="24" TT="COS" AR="0">
<Schedules>
<Schedule OnlyUntilFirstSuccess="0" FailIfNoSuccessInSched="0" RunEvenIfNotif="1">
<Days>
<DayOfWeek>Monday</DayOfWeek>
<DayOfWeek>Tuesday</DayOfWeek>
<DayOfWeek>Wednesday</DayOfWeek>
<DayOfWeek>Thursday</DayOfWeek>
<DayOfWeek>Friday</DayOfWeek>
<DayOfWeek>Saturday</DayOfWeek>
<DayOfWeek>Sunday</DayOfWeek>
</Days>
</Schedule>
</Schedules>
</Task>