我有看起来类似于以下内容的 xml
<Settings>
<CentralOnly>
<DateLists>
<DateList Name="name1" ID="1">
<Date>*-01-01</Date>
<Date>*-12-25</Date>
<Date>2007-05-28</Date>
<Date>2007-09-03</Date>
</DateList>
<DateList Name="name2" ID="2">
<Date>2008-11-11</Date>
<Date>2008-11-27</Date>
</DateList>
<DateList Name="name3" ID="3">
<Date>2008-03-21</Date>
<Date>2010-04-02</Date>
</DateList>
</DateLists>
</CentralOnly>
</Settings>
最终目标是将其放入 sql server 2008 r2 数据库中。我目前这样做的模式(很差)是将每一列写入一个单独的文本文件
dateID.txt | specificDate.txt
1 | *-01-01
1 | *-12-25
1 | 2007-05-28
1 | 2007-09-03
2 | 2008-11-11
2 | 2008-11-27
3 | 2008-03-21
2 | 2010-04-02
我相信下面的代码以这种方式在正确的轨道上(它还不起作用)。但是必须有一种方法可以用一个文件来做到这一点,也许是一个csv?
set-executionpolicy unrestricted
[xml]$config = Get-Content c:\path\config.xml
new-item c:\path\dlDays.txt -type file -force
new-item c:\path\dlDLID.txt -type file -force
$xml = $config.settings.DateLists.DateList | % $_.DateList{
$dateID = $_.id
$eachDate = $_.date | % $_.date{
$specificDate = $_.date
add-content c:\path\dlDays.txt $specificDate
add-content c:\path\dlDLID.txt $dateID
}
}