【发布时间】:2018-12-01 06:02:55
【问题描述】:
我有 100 个日期的 testDates.csv
日期 2017 年 1 月 10 日 2018 年 6 月 10 日 9/10/42 ...我制作了一个脚本,根据这些日期制作示例密码:
$file = Import-Csv -Path U:\Desktop\testDates.csv
foreach ($line in $file) {
$fullDate = $line.date
$year = Get-Date $fullDate -Format "yy"
$currentDate = Get-Date $fullDate -Format "MM-dd"
# Determining season
if ($currentDate -ge (Get-Date 01-01) -and $currentDate -lt (Get-Date 03-01)) {
$season = "Winter"
} elseif ($currentDate -ge (Get-Date 03-01) -and $currentDate -le (Get-Date 05-31)) {
$season = "Spring"
} elseif ($currentDate -ge (Get-Date 06-01) -and $currentDate -le (Get-Date 08-31)) {
$season = "Summer"
} elseif ($currentDate -ge (Get-Date 09-01) -and $currentDate -le (Get-Date 11-30)) {
$season = "Fall"
} elseif ($currentDate -ge (Get-Date 12-01) -and $currentDate -le (Get-Date 12-31)) {
$season = "Winter"
} else {
$season = "ClearyAnIntern"
}
# Creating password
$SamplePassword = $season + $year
}
我想将创建的密码导出回新列中的原始 .csv。所以在“日期”旁边有一列“密码”,看看我的脚本是否正常工作。示例:
日期密码 1/10/17 Winter17 2018 年 6 月 10 日夏季 18 9/10/42 秋季 42 ……我知道它涉及Export-Csv,但我不知道如何特别针对每一行进行管道传输。我一直在查看大量不同的线程和 MS 帮助中心,了解如何使用不同的参数,例如 -Append 等等,但我所看到和尝试的一切并不完全是我正在处理和从这些例子中推断出我目前的补救知识范围之外。我开始相信这可能涉及嵌套的 foreach 循环。
【问题讨论】:
-
是的,我正在研究北方气象而不是天文季节范围。夏天快乐。
标签: powershell csv powershell-3.0